Skip to main content

创建 Environment

创建一个运行环境。请求体定义沙箱类型、预装依赖与网络策略;响应返回完整的 Environment 对象。

前提

已完成 Endpoint 与鉴权配置,详见API 总览与认证。

接口

POST /environments

请求体

字段必填类型说明
name是string工作空间内唯一标识
description否string环境用途说明
scope否string作用域。organization:工作空间全部成员可见与复用。默认 organization
config.type否stringcloud 云端容器。创建后不可修改。未传入 config 时服务端默认补全为 cloud
config.packages否object预装依赖,按包管理器分组。键为 apt / pip / npm,值为包名数组。安装可能需要预热时间,完成前环境不可被会话绑定
config.networking否object网络策略对象,结构 {"type": "unrestricted"},目前仅支持放行全部出站访问
metadata否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"}
    }
  }'

响应示例

{
  "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 对象。字段如下:

响应字段

字段类型说明
idstring环境 ID,格式 env_<base64 编码字符串>,示例值 env_N2M2OTc4NTY4ZjRkNDEwZT
typestring固定为 environment
name / description / scope / config / metadatastring / object同请求体;config 为完整运行时配置(沙箱类型、预装依赖、网络策略)
archived_atstring / null归档时间,未归档时为 null
created_at / updated_atstring创建 / 最近更新时间,ISO 8601
requestIdstring本次请求的唯一标识
Managed Agent API
Flow Agent API
Sandbox API
RAG API
长期记忆
ParseX API
Security API
框架集成
Assistant API(下线中)