Skip to main content
Environments

Environment 数据结构

Environment 对象及其配置子结构的完整定义。

Environment 对象

由创建、获取、列表、更新和归档接口返回。
字段类型说明
idstringEnvironment ID,前缀 env_
typestring固定为 "environment"
namestring环境名称
descriptionstring环境描述
configEnvironment config环境配置
metadataobjectMetadata 对象。默认 {}
archived_atstring | nullUTC 归档时间,未归档时为 null
created_atstringUTC 创建时间
updated_atstringUTC 最后更新时间

Environment config

字段类型必填说明
typestring"cloud""self_hosted"
networkingEnvironment networking网络访问配置
packagesEnvironment packages环境关联的包声明
setup_scriptstring用户初始化脚本。参见 Environment setup script
type"self_hosted" 时,config 仅允许:
{"type": "self_hosted"}
其他配置字段仅在 type"cloud" 时有效。

Environment packages

packages 将包管理器映射到包名数组。Cloud 环境响应中包含 type 以及 aptnpmpip;省略的数组返回为 []
字段类型说明示例
typestring响应中固定为 "packages""packages"
aptarray of stringDebian/Ubuntu 系统包声明["git", "curl", "build-essential"]
npmarray of stringNode.js 包声明["typescript@5.0.0", "eslint"]
piparray of stringPython 包声明["pandas", "PyYAML==6.0.1"]

Environment setup script

setup_script 是在沙箱准备阶段执行的 shell 脚本,在 packages 安装完成后运行,通过 /bin/bash -lc 解释执行。适用于无法通过 packages 表达的初始化步骤,如克隆仓库、写入配置文件或预热缓存。
约束
类型string
最大长度64 KB
解释器/bin/bash -lc
超时10 分钟
执行时机沙箱准备阶段,packages 安装之后
脚本成功后会在沙箱内写入完成标记,不会在同一沙箱中重复执行;沙箱重建时脚本会重新运行。 非零退出码会中止 Session 启动。错误响应中包含 setup_script 的退出码和 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_hostsarray of string主机白名单。默认 []
allow_package_managersboolean包管理器访问标志。默认 false
allow_mcp_serversbooleanMCP 服务器访问标志。默认 false