创建一个运行环境。请求体定义沙箱类型、预装依赖与网络策略;响应返回完整的 Environment 对象。
前提
已完成 Endpoint 与鉴权配置,详见API 总览与认证。
接口
POST /environments
请求体
|
字段 |
必填 |
类型 |
说明 |
|
|
是 |
string |
工作空间内唯一标识 |
|
|
否 |
string |
环境用途说明 |
|
|
否 |
string |
|
|
|
否 |
string |
|
|
|
否 |
object |
预装依赖,按包管理器分组。键为 |
|
|
否 |
object |
网络策略对象,结构 |
|
|
否 |
object |
业务自定义键值,不影响运行行为 |
请求示例
curl -X POST "$AGENTSTUDIO_URL/environments" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "data-sandbox",
"description": "数据分析沙箱",
"scope": "organization",
"metadata": {"team": "infra"},
"config": {
"type": "cloud",
"packages": {
"apt": ["ffmpeg"],
"pip": ["pandas", "numpy", "matplotlib"]
},
"networking": {"type": "unrestricted"}
}
}'env = client.environments.create(
name="data-sandbox",
config={
"type": "cloud",
"networking": {"type": "unrestricted"},
"packages": {
"apt": ["ffmpeg"],
"pip": ["pandas", "numpy", "matplotlib"],
},
},
description="数据分析沙箱",
scope="organization",
metadata={"team": "infra"},
)Environment env = client.environments().create(EnvironmentCreateParam.builder()
.name("data-sandbox")
.description("数据分析沙箱")
.build());响应示例
{
"id": "env_xxx",
"type": "environment",
"name": "data-sandbox",
"description": "数据分析沙箱",
"scope": "organization",
"config": {
"type": "cloud",
"packages": {"apt": ["ffmpeg"], "pip": ["pandas", "numpy", "matplotlib"]},
"networking": {"type": "unrestricted"}
},
"metadata": {"team": "infra"},
"archived_at": null,
"created_at": "2026-06-16T12:45:34+08:00",
"updated_at": "2026-06-16T12:45:34+08:00",
"requestId": "xxx"
}
响应为 Environment 对象。字段如下:
响应字段
|
字段 |
类型 |
说明 |
|
|
string |
环境 ID,格式 |
|
|
string |
固定为 |
|
|
string / object |
同请求体; |
|
|
string | null |
归档时间,未归档时为 |
|
|
string |
创建/最近更新时间,ISO 8601 |
|
|
string |
本次请求的唯一标识 |
该文章对您有帮助吗?