创建环境
curl --request POST \
--url https://api.moonshot.cn/v1/environments \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Data analysis",
"config": {
"type": "cloud",
"networking": {
"type": "limited",
"allowed_hosts": [
"example.invalid"
]
},
"packages": {
"pip": [
"pandas==2.3.2"
]
},
"setup_script": "mkdir -p /workspace/output"
}
}
'import requests
url = "https://api.moonshot.cn/v1/environments"
payload = {
"name": "Data analysis",
"config": {
"type": "cloud",
"networking": {
"type": "limited",
"allowed_hosts": ["example.invalid"]
},
"packages": { "pip": ["pandas==2.3.2"] },
"setup_script": "mkdir -p /workspace/output"
}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Data analysis',
config: {
type: 'cloud',
networking: {type: 'limited', allowed_hosts: ['example.invalid']},
packages: {pip: ['pandas==2.3.2']},
setup_script: 'mkdir -p /workspace/output'
}
})
};
fetch('https://api.moonshot.cn/v1/environments', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.cn/v1/environments",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'Data analysis',
'config' => [
'type' => 'cloud',
'networking' => [
'type' => 'limited',
'allowed_hosts' => [
'example.invalid'
]
],
'packages' => [
'pip' => [
'pandas==2.3.2'
]
],
'setup_script' => 'mkdir -p /workspace/output'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/environments"
payload := strings.NewReader("{\n \"name\": \"Data analysis\",\n \"config\": {\n \"type\": \"cloud\",\n \"networking\": {\n \"type\": \"limited\",\n \"allowed_hosts\": [\n \"example.invalid\"\n ]\n },\n \"packages\": {\n \"pip\": [\n \"pandas==2.3.2\"\n ]\n },\n \"setup_script\": \"mkdir -p /workspace/output\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/v1/environments")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Data analysis\",\n \"config\": {\n \"type\": \"cloud\",\n \"networking\": {\n \"type\": \"limited\",\n \"allowed_hosts\": [\n \"example.invalid\"\n ]\n },\n \"packages\": {\n \"pip\": [\n \"pandas==2.3.2\"\n ]\n },\n \"setup_script\": \"mkdir -p /workspace/output\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/environments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"Data analysis\",\n \"config\": {\n \"type\": \"cloud\",\n \"networking\": {\n \"type\": \"limited\",\n \"allowed_hosts\": [\n \"example.invalid\"\n ]\n },\n \"packages\": {\n \"pip\": [\n \"pandas==2.3.2\"\n ]\n },\n \"setup_script\": \"mkdir -p /workspace/output\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "env_01h455vb4pex5vsknk084sn02q",
"name": "Data analysis",
"description": "用于数据分析任务的执行环境",
"config": {
"type": "cloud",
"networking": {
"type": "limited",
"allowed_hosts": [
"example.invalid"
]
},
"packages": {
"pip": [
"pandas==2.3.2"
]
},
"setup_script": "mkdir -p /workspace/output"
},
"metadata": {},
"build_status": "building",
"created_at": "2026-08-26T12:00:00.000Z",
"updated_at": "2026-08-26T12:00:00.000Z",
"scope": "project"
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}创建一个环境,将其配置冻结为不可变版本 "1",并开始构建。
最新版本的 build_status 报告 ready 后,会话即可使用该环境。名称不要求唯一。
POST
/
v1
/
environments
创建环境
curl --request POST \
--url https://api.moonshot.cn/v1/environments \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Data analysis",
"config": {
"type": "cloud",
"networking": {
"type": "limited",
"allowed_hosts": [
"example.invalid"
]
},
"packages": {
"pip": [
"pandas==2.3.2"
]
},
"setup_script": "mkdir -p /workspace/output"
}
}
'import requests
url = "https://api.moonshot.cn/v1/environments"
payload = {
"name": "Data analysis",
"config": {
"type": "cloud",
"networking": {
"type": "limited",
"allowed_hosts": ["example.invalid"]
},
"packages": { "pip": ["pandas==2.3.2"] },
"setup_script": "mkdir -p /workspace/output"
}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Data analysis',
config: {
type: 'cloud',
networking: {type: 'limited', allowed_hosts: ['example.invalid']},
packages: {pip: ['pandas==2.3.2']},
setup_script: 'mkdir -p /workspace/output'
}
})
};
fetch('https://api.moonshot.cn/v1/environments', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.cn/v1/environments",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'Data analysis',
'config' => [
'type' => 'cloud',
'networking' => [
'type' => 'limited',
'allowed_hosts' => [
'example.invalid'
]
],
'packages' => [
'pip' => [
'pandas==2.3.2'
]
],
'setup_script' => 'mkdir -p /workspace/output'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/environments"
payload := strings.NewReader("{\n \"name\": \"Data analysis\",\n \"config\": {\n \"type\": \"cloud\",\n \"networking\": {\n \"type\": \"limited\",\n \"allowed_hosts\": [\n \"example.invalid\"\n ]\n },\n \"packages\": {\n \"pip\": [\n \"pandas==2.3.2\"\n ]\n },\n \"setup_script\": \"mkdir -p /workspace/output\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/v1/environments")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Data analysis\",\n \"config\": {\n \"type\": \"cloud\",\n \"networking\": {\n \"type\": \"limited\",\n \"allowed_hosts\": [\n \"example.invalid\"\n ]\n },\n \"packages\": {\n \"pip\": [\n \"pandas==2.3.2\"\n ]\n },\n \"setup_script\": \"mkdir -p /workspace/output\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/environments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"Data analysis\",\n \"config\": {\n \"type\": \"cloud\",\n \"networking\": {\n \"type\": \"limited\",\n \"allowed_hosts\": [\n \"example.invalid\"\n ]\n },\n \"packages\": {\n \"pip\": [\n \"pandas==2.3.2\"\n ]\n },\n \"setup_script\": \"mkdir -p /workspace/output\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "env_01h455vb4pex5vsknk084sn02q",
"name": "Data analysis",
"description": "用于数据分析任务的执行环境",
"config": {
"type": "cloud",
"networking": {
"type": "limited",
"allowed_hosts": [
"example.invalid"
]
},
"packages": {
"pip": [
"pandas==2.3.2"
]
},
"setup_script": "mkdir -p /workspace/output"
},
"metadata": {},
"build_status": "building",
"created_at": "2026-08-26T12:00:00.000Z",
"updated_at": "2026-08-26T12:00:00.000Z",
"scope": "project"
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}请求头
可选的幂等键。相同的键与请求体会在 24 小时内重放首个响应;以不同的请求体复用,或在首个请求仍在处理时复用,返回 409。
请求体
application/json
响应
已创建的环境。其首个版本正在构建(构建管道开启时 build_status 为 building)。
持久化的执行环境,用于托管智能体会话。
环境 ID。
Pattern:
^env_[0-9a-hjkmnp-tv-z]{26}$人类可读的环境名称。
执行配置。
Show child attributes
Show child attributes
创建时间戳。
上次更新时间戳。
可见性范围。
可用选项:
official, org, project, user 可选的人类可读描述。
用户自定义元数据(最多 16 条)。
Show child attributes
Show child attributes
最新版本快照构建的生命周期状态。
可用选项:
building, ready, failed 归档时间戳。活跃期间缺省。已归档的环境为只读:不可新建会话,已有会话不受影响,且不可取消归档。
此页面对您有帮助吗?