Skip to main content
Environments

Environment 结构

Environment 对象和配置字段结构。

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"
packagesEnvironment packagesEnvironment 关联的包声明
setup_scriptstring用户 setup script 文本,详见 Environment setup script
self_hosted config 可以包含 type 和可选的 setup_script
{"type": "self_hosted", "setup_script": "./initialize-worker.sh"}
self_hosted config 仅支持 type 和可选的 setup_script

Environment packages

packages 是包管理器到软件包规格字符串数组的映射。请求支持 aptnpmpip。Cloud Environment 响应还会返回若干保留字段;省略的数组会返回为 []
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"]
cargostring 数组响应中的保留字段;当前不支持通过该字段安装依赖[]
gemstring 数组响应中的保留字段;当前不支持通过该字段安装依赖[]
gostring 数组响应中的保留字段;当前不支持通过该字段安装依赖[]

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",
    "setup_script": "set -euo pipefail\n[ -d /data/workspace/repo/.git ] || git clone https://github.com/me/repo /data/workspace/repo\ncd /data/workspace/repo && pnpm install --frozen-lockfile"
  }
}