跳转到主要内容

Environment 对象

创建、查询、列表、更新和归档接口都会返回该结构。
字段类型说明
idstringEnvironment ID,前缀为 env_
typestring固定值 "environment"
namestringEnvironment 名称
descriptionstringEnvironment 描述
configEnvironment configEnvironment 配置
metadataobjectMetadata 对象,默认 {}
archived_atstring | nullUTC 归档时间;未归档时为 null
created_atstringUTC 创建时间
updated_atstringUTC 最后更新时间

Environment config

字段类型必填说明
typestring"cloud""self_hosted"
networkingEnvironment networking网络访问配置
packagesEnvironment packagesEnvironment 关联的包声明
setup_scriptstring用户 setup script 文本,详见 Environment setup script
self_hosted config 必须严格为:
{"type": "self_hosted"}
其他 config 字段仅适用于 type"cloud" 的 Environment。

Environment packages

packages 是包管理器到软件包规格字符串数组的映射。Cloud Environment 响应会包含 type 以及 aptnpmpip;省略的数组会返回为 []
key类型说明示例
typestring响应中固定为 "packages""packages"
aptstring 数组Debian/Ubuntu 系统包声明["git", "curl", "build-essential"]
npmstring 数组Node.js package 声明["typescript@5.0.0", "eslint"]
pipstring 数组Python package 声明["pandas", "PyYAML==6.0.1"]

Environment setup script

setup_script 是 sandbox 准备阶段、packages 安装完成之后执行的一段 shell 脚本,用 /bin/bash -lc 运行。常用于克隆代码、写配置文件、warmup 缓存等无法用 packages 表达的初始化步骤。
约束
类型string
最大长度64 KB
解释器/bin/bash -lc
超时10 分钟
执行时机sandbox 准备阶段,packages 安装完成之后
执行成功后会在沙箱内写入完成标记,本次 sandbox 内不会重复执行;沙箱被回收重建后会再次执行。 脚本以非零状态退出会导致 Session 启动失败。错误响应中会带上 setup_script 的 exit code 与 stderr 摘要,便于定位失败原因。
{
  "config": {
    "type": "cloud",
    "networking": {"type": "unrestricted"},
    "setup_script": "set -euo pipefail\n[ -d /workspace/.git ] || git clone https://github.com/me/repo /workspace\ncd /workspace && pnpm install --frozen-lockfile"
  }
}

Environment networking

字段类型必填说明
typestring可选值:limitedunrestricted
allowed_hostsstring 数组随 config 返回的 host allowlist,默认 []
allow_package_managersboolean随 config 返回的 package manager 访问标记,默认 false
allow_mcp_serversboolean随 config 返回的 MCP server 访问标记,默认 false

相关

云端环境

选择 Agent 运行的容器、网络与依赖。