Environments
Create Environment
post /v1/environments
Create a new environment with the specified configuration.
Header Parameters
-
"anthropic-beta": optional array of AnthropicBetaOptional header to specify the beta version(s) you want to use.
-
string -
"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 22 more-
"message-batches-2024-09-24" -
"prompt-caching-2024-07-31" -
"computer-use-2024-10-22" -
"computer-use-2025-01-24" -
"pdfs-2024-09-25" -
"token-counting-2024-11-01" -
"token-efficient-tools-2025-02-19" -
"output-128k-2025-02-19" -
"files-api-2025-04-14" -
"mcp-client-2025-04-04" -
"mcp-client-2025-11-20" -
"dev-full-thinking-2025-05-14" -
"interleaved-thinking-2025-05-14" -
"code-execution-2025-05-22" -
"extended-cache-ttl-2025-04-11" -
"context-1m-2025-08-07" -
"context-management-2025-06-27" -
"model-context-window-exceeded-2025-08-26" -
"skills-2025-10-02" -
"fast-mode-2026-02-01" -
"output-300k-2026-03-24" -
"user-profiles-2026-03-24" -
"advisor-tool-2026-03-01" -
"managed-agents-2026-04-01" -
"cache-diagnosis-2026-04-07"
-
-
Body Parameters
-
name: string环境的可读名称
-
config: optional BetaCloudConfigParams or BetaSelfHostedConfigParams环境配置
-
BetaCloudConfigParams object { type, networking, packages }cloud环境配置的请求参数。字段默认为 null;更新时,省略的字段将保留现有值。
-
type: "cloud"环境类型
"cloud"
-
networking: optional BetaUnrestrictedNetwork or BetaLimitedNetworkParams网络配置策略。更新时省略可保留现有值。
-
BetaUnrestrictedNetwork object { type }无限制的网络访问。
-
type: "unrestricted"网络策略类型
"unrestricted"
-
-
BetaLimitedNetworkParams object { type, allow_mcp_servers, allow_package_managers, allowed_hosts }有限网络请求参数。
字段默认为 null;更新时,省略的字段将保留现有值。
-
type: "limited"网络策略类型
"limited"
-
allow_mcp_servers: optional boolean允许出站访问代理上配置的 MCP 服务器端点,超出
allowed_hosts数组中列出的范围。默认为false。 -
allow_package_managers: optional boolean允许出站访问公共包注册中心(PyPI、npm 等),超出
allowed_hosts数组中列出的范围。默认为false。 -
allowed_hosts: optional array of string指定容器可以访问的域名。
-
-
-
packages: optional BetaPackagesParams指定此环境中可用的包(可选版本)。
使用版本号时,请使用与包管理器相关的版本语义,例如对于
pip使用package==1.0.0。您需要自行验证包和版本是否存在。不指定版本将安装最新版本。-
apt: optional array of string要安装的 Ubuntu/Debian 包
-
cargo: optional array of string要安装的 Rust 包
-
gem: optional array of string要安装的 Ruby 包
-
go: optional array of string要安装的 Go 包
-
npm: optional array of string要安装的 Node.js 包
-
pip: optional array of string要安装的 Python 包
-
type: optional "packages"包配置类型
"packages"
-
-
-
BetaSelfHostedConfigParams object { type }self_hosted环境配置的请求参数。-
type: "self_hosted"环境类型
"self_hosted"
-
-
-
description: optional string环境的可选描述
-
metadata: optional map[string]用户提供的元数据键值对
-
scope: optional "organization" or "account"此环境的可见范围。'organization' 使环境对所有账户可见。'account' 将可见性限制为仅拥有账户。仅适用于自托管环境。如果未指定,则根据组织类型设置默认值。
-
"organization" -
"account"
-
Returns
-
BetaEnvironment object { id, archived_at, config, 7 more }用于云环境和自托管环境的统一环境资源。
-
id: string环境标识符(例如 'env_...')
-
archived_at: string环境归档时的 RFC 3339 时间戳,如果未归档则为 null
-
config: BetaCloudConfig or BetaSelfHostedConfig环境配置(Anthropic Cloud 或自托管)
-
BetaCloudConfig object { networking, packages, type }cloud环境配置。-
networking: BetaUnrestrictedNetwork or BetaLimitedNetwork网络配置策略。
-
BetaUnrestrictedNetwork object { type }无限制的网络访问。
-
type: "unrestricted"网络策略类型
"unrestricted"
-
-
BetaLimitedNetwork object { allow_mcp_servers, allow_package_managers, allowed_hosts, type }有限的网络访问。
-
allow_mcp_servers: boolean允许出站访问代理上配置的 MCP 服务器端点,超出
allowed_hosts数组中列出的范围。 -
allow_package_managers: boolean允许出站访问公共包注册中心(PyPI、npm 等),超出
allowed_hosts数组中列出的范围。 -
allowed_hosts: array of string指定容器可以访问的域名。
-
type: "limited"网络策略类型
"limited"
-
-
-
packages: BetaPackages包管理器配置。
-
apt: array of string要安装的 Ubuntu/Debian 包
-
cargo: array of string要安装的 Rust 包
-
gem: array of string要安装的 Ruby 包
-
go: array of string要安装的 Go 包
-
npm: array of string要安装的 Node.js 包
-
pip: array of string要安装的 Python 包
-
type: optional "packages"包配置类型
"packages"
-
-
type: "cloud"环境类型
"cloud"
-
-
BetaSelfHostedConfig object { type }自托管环境的配置。
-
type: "self_hosted"环境类型
"self_hosted"
-
-
-
created_at: string环境创建时的 RFC 3339 时间戳
-
description: string用户提供的环境描述
-
metadata: map[string]用户提供的元数据键值对
-
name: string环境的可读名称
-
type: "environment"对象类型(始终为 'environment')
"environment"
-
updated_at: string环境最后更新时的 RFC 3339 时间戳
-
scope: optional "organization" or "account"此环境的可见范围。'organization' 表示对所有账户可见。'account' 表示仅对拥有账户可见。
-
"organization" -
"account"
-
-
Example
curl https://api.anthropic.com/v1/environments \
-H 'Content-Type: application/json' \
-H 'anthropic-version: 2023-06-01' \
-H 'anthropic-beta: managed-agents-2026-04-01' \
-H "X-Api-Key: $ANTHROPIC_API_KEY" \
-d '{
"name": "python-data-analysis",
"config": {
"type": "cloud",
"networking": {
"type": "limited",
"allow_package_managers": true,
"allowed_hosts": [
"api.example.com"
]
},
"packages": {
"pip": [
"pandas",
"numpy"
]
}
},
"description": "Python environment with data-analysis packages."
}'
Response
{
"id": "env_011CZkZ9X2dpNyB7HsEFoRfW",
"archived_at": null,
"config": {
"networking": {
"allow_mcp_servers": false,
"allow_package_managers": true,
"allowed_hosts": [
"api.example.com"
],
"type": "limited"
},
"packages": {
"apt": [
"string"
],
"cargo": [
"string"
],
"gem": [
"string"
],
"go": [
"string"
],
"npm": [
"string"
],
"pip": [
"pandas",
"numpy"
],
"type": "packages"
},
"type": "cloud"
},
"created_at": "2026-03-15T10:00:00Z",
"description": "Python environment with data-analysis packages.",
"metadata": {},
"name": "python-data-analysis",
"type": "environment",
"updated_at": "2026-03-15T10:00:00Z",
"scope": "organization"
}
List Environments
get /v1/environments
列出支持分页的环境列表。
Query Parameters
-
include_archived: optional boolean在响应中包含已归档的环境
-
limit: optional number返回的最大环境数量
-
page: optional string用于分页的上一个响应中的不透明游标。传递上一个响应中的
next_page值。
Header Parameters
-
"anthropic-beta": optional array of AnthropicBeta可选的请求头,用于指定要使用的 beta 版本。
-
string -
"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 22 more-
"message-batches-2024-09-24" -
"prompt-caching-2024-07-31" -
"computer-use-2024-10-22" -
"computer-use-2025-01-24" -
"pdfs-2024-09-25" -
"token-counting-2024-11-01" -
"token-efficient-tools-2025-02-19" -
"output-128k-2025-02-19" -
"files-api-2025-04-14" -
"mcp-client-2025-04-04" -
"mcp-client-2025-11-20" -
"dev-full-thinking-2025-05-14" -
"interleaved-thinking-2025-05-14" -
"code-execution-2025-05-22" -
"extended-cache-ttl-2025-04-11" -
"context-1m-2025-08-07" -
"context-management-2025-06-27" -
"model-context-window-exceeded-2025-08-26" -
"skills-2025-10-02" -
"fast-mode-2026-02-01" -
"output-300k-2026-03-24" -
"user-profiles-2026-03-24" -
"advisor-tool-2026-03-01" -
"managed-agents-2026-04-01" -
"cache-diagnosis-2026-04-07"
-
-
Returns
-
data: array of BetaEnvironment环境列表。
-
id: string环境标识符(例如 'env_...')
-
archived_at: string环境归档时的 RFC 3339 时间戳,如果未归档则为 null
-
config: BetaCloudConfig or BetaSelfHostedConfig环境配置(Anthropic Cloud 或自托管)
-
BetaCloudConfig object { networking, packages, type }cloud环境配置。-
networking: BetaUnrestrictedNetwork or BetaLimitedNetwork网络配置策略。
-
BetaUnrestrictedNetwork object { type }无限制的网络访问。
-
type: "unrestricted"网络策略类型
"unrestricted"
-
-
BetaLimitedNetwork object { allow_mcp_servers, allow_package_managers, allowed_hosts, type }有限的网络访问。
-
allow_mcp_servers: boolean允许出站访问代理上配置的 MCP 服务器端点,超出
allowed_hosts数组中列出的范围。 -
allow_package_managers: boolean允许出站访问公共包注册中心(PyPI、npm 等),超出
allowed_hosts数组中列出的范围。 -
allowed_hosts: array of string指定容器可以访问的域名。
-
type: "limited"网络策略类型
"limited"
-
-
-
packages: BetaPackages包管理器配置。
-
apt: array of string要安装的 Ubuntu/Debian 包
-
cargo: array of string要安装的 Rust 包
-
gem: array of string要安装的 Ruby 包
-
go: array of string要安装的 Go 包
-
npm: array of string要安装的 Node.js 包
-
pip: array of string要安装的 Python 包
-
type: optional "packages"包配置类型
"packages"
-
-
type: "cloud"环境类型
"cloud"
-
-
BetaSelfHostedConfig object { type }自托管环境的配置。
-
type: "self_hosted"环境类型
"self_hosted"
-
-
-
created_at: string环境创建时的 RFC 3339 时间戳
-
description: string用户提供的环境描述
-
metadata: map[string]用户提供的元数据键值对
-
name: string环境的可读名称
-
type: "environment"对象类型(始终为 'environment')
"environment"
-
updated_at: string环境最后更新时的 RFC 3339 时间戳
-
scope: optional "organization" or "account"此环境的可见范围。'organization' 表示对所有账户可见。'account' 表示仅对拥有账户可见。
-
"organization" -
"account"
-
-
-
next_page: string用于获取下一页结果的令牌。如果为
null,则没有更多可用结果。将此值传递给下一个请求中的page参数。
Example
curl https://api.anthropic.com/v1/environments \
-H 'anthropic-version: 2023-06-01' \
-H 'anthropic-beta: managed-agents-2026-04-01' \
-H "X-Api-Key: $ANTHROPIC_API_KEY"
Response
{
"data": [
{
"id": "env_011CZkZ9X2dpNyB7HsEFoRfW",
"archived_at": null,
"config": {
"networking": {
"allow_mcp_servers": false,
"allow_package_managers": true,
"allowed_hosts": [
"api.example.com"
],
"type": "limited"
},
"packages": {
"apt": [
"string"
],
"cargo": [
"string"
],
"gem": [
"string"
],
"go": [
"string"
],
"npm": [
"string"
],
"pip": [
"pandas",
"numpy"
],
"type": "packages"
},
"type": "cloud"
},
"created_at": "2026-03-15T10:00:00Z",
"description": "Python environment with data-analysis packages.",
"metadata": {},
"name": "python-data-analysis",
"type": "environment",
"updated_at": "2026-03-15T10:00:00Z",
"scope": "organization"
}
],
"next_page": "page_MjAyNS0wNS0xNFQwMDowMDowMFo="
}
Get Environment
get /v1/environments/{environment_id}
通过 ID 获取特定环境。
Path Parameters
environment_id: string
Header Parameters
-
"anthropic-beta": optional array of AnthropicBeta可选的请求头,用于指定要使用的 beta 版本。
-
string -
"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 22 more-
"message-batches-2024-09-24" -
"prompt-caching-2024-07-31" -
"computer-use-2024-10-22" -
"computer-use-2025-01-24" -
"pdfs-2024-09-25" -
"token-counting-2024-11-01" -
"token-efficient-tools-2025-02-19" -
"output-128k-2025-02-19" -
"files-api-2025-04-14" -
"mcp-client-2025-04-04" -
"mcp-client-2025-11-20" -
"dev-full-thinking-2025-05-14" -
"interleaved-thinking-2025-05-14" -
"code-execution-2025-05-22" -
"extended-cache-ttl-2025-04-11" -
"context-1m-2025-08-07" -
"context-management-2025-06-27" -
"model-context-window-exceeded-2025-08-26" -
"skills-2025-10-02" -
"fast-mode-2026-02-01" -
"output-300k-2026-03-24" -
"user-profiles-2026-03-24" -
"advisor-tool-2026-03-01" -
"managed-agents-2026-04-01" -
"cache-diagnosis-2026-04-07"
-
-
Returns
-
BetaEnvironment object { id, archived_at, config, 7 more }用于云环境和自托管环境的统一环境资源。
-
id: string环境标识符(例如 'env_...')
-
archived_at: string环境归档时的 RFC 3339 时间戳,如果未归档则为 null
-
config: BetaCloudConfig or BetaSelfHostedConfig环境配置(Anthropic Cloud 或自托管)
-
BetaCloudConfig object { networking, packages, type }cloud环境配置。-
networking: BetaUnrestrictedNetwork or BetaLimitedNetwork网络配置策略。
-
BetaUnrestrictedNetwork object { type }无限制的网络访问。
-
type: "unrestricted"网络策略类型
"unrestricted"
-
-
BetaLimitedNetwork object { allow_mcp_servers, allow_package_managers, allowed_hosts, type }有限的网络访问。
-
allow_mcp_servers: boolean允许出站访问代理上配置的 MCP 服务器端点,超出
allowed_hosts数组中列出的范围。 -
allow_package_managers: boolean允许出站访问公共包注册中心(PyPI、npm 等),超出
allowed_hosts数组中列出的范围。 -
allowed_hosts: array of string指定容器可以访问的域名。
-
type: "limited"网络策略类型
"limited"
-
-
-
packages: BetaPackages包管理器配置。
-
apt: array of string要安装的 Ubuntu/Debian 包
-
cargo: array of string要安装的 Rust 包
-
gem: array of string要安装的 Ruby 包
-
go: array of string要安装的 Go 包
-
npm: array of string要安装的 Node.js 包
-
pip: array of string要安装的 Python 包
-
type: optional "packages"包配置类型
"packages"
-
-
type: "cloud"环境类型
"cloud"
-
-
BetaSelfHostedConfig object { type }自托管环境的配置。
-
type: "self_hosted"环境类型
"self_hosted"
-
-
-
created_at: string环境创建时的 RFC 3339 时间戳
-
description: string用户提供的环境描述
-
metadata: map[string]用户提供的元数据键值对
-
name: string环境的可读名称
-
type: "environment"对象类型(始终为 'environment')
"environment"
-
updated_at: string环境最后更新时的 RFC 3339 时间戳
-
scope: optional "organization" or "account"此环境的可见范围。'organization' 表示对所有账户可见。'account' 表示仅对拥有账户可见。
-
"organization" -
"account"
-
-
Example
curl https://api.anthropic.com/v1/environments/$ENVIRONMENT_ID \
-H 'anthropic-version: 2023-06-01' \
-H 'anthropic-beta: managed-agents-2026-04-01' \
-H "X-Api-Key: $ANTHROPIC_API_KEY"
Response
{
"id": "env_011CZkZ9X2dpNyB7HsEFoRfW",
"archived_at": null,
"config": {
"networking": {
"allow_mcp_servers": false,
"allow_package_managers": true,
"allowed_hosts": [
"api.example.com"
],
"type": "limited"
},
"packages": {
"apt": [
"string"
],
"cargo": [
"string"
],
"gem": [
"string"
],
"go": [
"string"
],
"npm": [
"string"
],
"pip": [
"pandas",
"numpy"
],
"type": "packages"
},
"type": "cloud"
},
"created_at": "2026-03-15T10:00:00Z",
"description": "Python environment with data-analysis packages.",
"metadata": {},
"name": "python-data-analysis",
"type": "environment",
"updated_at": "2026-03-15T10:00:00Z",
"scope": "organization"
}
Update Environment
post /v1/environments/{environment_id}
更新现有环境的配置。
Path Parameters
environment_id: string
Header Parameters
-
"anthropic-beta": optional array of AnthropicBeta可选的请求头,用于指定要使用的 beta 版本。
-
string -
"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 22 more-
"message-batches-2024-09-24" -
"prompt-caching-2024-07-31" -
"computer-use-2024-10-22" -
"computer-use-2025-01-24" -
"pdfs-2024-09-25" -
"token-counting-2024-11-01" -
"token-efficient-tools-2025-02-19" -
"output-128k-2025-02-19" -
"files-api-2025-04-14" -
"mcp-client-2025-04-04" -
"mcp-client-2025-11-20" -
"dev-full-thinking-2025-05-14" -
"interleaved-thinking-2025-05-14" -
"code-execution-2025-05-22" -
"extended-cache-ttl-2025-04-11" -
"context-1m-2025-08-07" -
"context-management-2025-06-27" -
"model-context-window-exceeded-2025-08-26" -
"skills-2025-10-02" -
"fast-mode-2026-02-01" -
"output-300k-2026-03-24" -
"user-profiles-2026-03-24" -
"advisor-tool-2026-03-01" -
"managed-agents-2026-04-01" -
"cache-diagnosis-2026-04-07"
-
-
Body Parameters
-
config: optional BetaCloudConfigParams or BetaSelfHostedConfigParams更新后的环境配置
-
BetaCloudConfigParams object { type, networking, packages }cloud环境配置的请求参数。字段默认为 null;更新时,省略的字段将保留现有值。
-
type: "cloud"环境类型
"cloud"
-
networking: optional BetaUnrestrictedNetwork or BetaLimitedNetworkParams网络配置策略。更新时省略可保留现有值。
-
BetaUnrestrictedNetwork object { type }无限制的网络访问。
-
type: "unrestricted"网络策略类型
"unrestricted"
-
-
BetaLimitedNetworkParams object { type, allow_mcp_servers, allow_package_managers, allowed_hosts }有限网络请求参数。
字段默认为 null;更新时,省略的字段将保留现有值。
-
type: "limited"网络策略类型
"limited"
-
allow_mcp_servers: optional boolean允许出站访问代理上配置的 MCP 服务器端点,超出
allowed_hosts数组中列出的范围。默认为false。 -
allow_package_managers: optional boolean允许出站访问公共包注册中心(PyPI、npm 等),超出
allowed_hosts数组中列出的范围。默认为false。 -
allowed_hosts: optional array of string指定容器可以访问的域名。
-
-
-
packages: optional BetaPackagesParams指定此环境中可用的包(可选版本)。
使用版本号时,请使用与包管理器相关的版本语义,例如对于
pip使用package==1.0.0。您需要自行验证包和版本是否存在。不指定版本将安装最新版本。-
apt: optional array of string要安装的 Ubuntu/Debian 包
-
cargo: optional array of string要安装的 Rust 包
-
gem: optional array of string要安装的 Ruby 包
-
go: optional array of string要安装的 Go 包
-
npm: optional array of string要安装的 Node.js 包
-
pip: optional array of string要安装的 Python 包
-
type: optional "packages"包配置类型
"packages"
-
-
-
BetaSelfHostedConfigParams object { type }self_hosted环境配置的请求参数。-
type: "self_hosted"环境类型
"self_hosted"
-
-
-
description: optional string更新后的环境描述
-
metadata: optional map[string]用户提供的元数据键值对。将值设置为 null 或空字符串可删除该键。
-
name: optional string更新后的环境名称
-
scope: optional "organization" or "account"此环境的可见范围。'organization' 使环境对所有账户可见。'account' 将可见性限制为仅拥有账户。
-
"organization" -
"account"
-
Returns
-
BetaEnvironment object { id, archived_at, config, 7 more }用于云环境和自托管环境的统一环境资源。
-
id: string环境标识符(例如 'env_...')
-
archived_at: string环境归档时的 RFC 3339 时间戳,如果未归档则为 null
-
config: BetaCloudConfig or BetaSelfHostedConfig环境配置(Anthropic Cloud 或自托管)
-
BetaCloudConfig object { networking, packages, type }cloud环境配置。-
networking: BetaUnrestrictedNetwork or BetaLimitedNetwork网络配置策略。
-
BetaUnrestrictedNetwork object { type }无限制的网络访问。
-
type: "unrestricted"网络策略类型
"unrestricted"
-
-
BetaLimitedNetwork object { allow_mcp_servers, allow_package_managers, allowed_hosts, type }有限的网络访问。
-
allow_mcp_servers: boolean允许出站访问代理上配置的 MCP 服务器端点,超出
allowed_hosts数组中列出的范围。 -
allow_package_managers: boolean允许出站访问公共包注册中心(PyPI、npm 等),超出
allowed_hosts数组中列出的范围。 -
allowed_hosts: array of string指定容器可以访问的域名。
-
type: "limited"网络策略类型
"limited"
-
-
-
packages: BetaPackages包管理器配置。
-
apt: array of string要安装的 Ubuntu/Debian 包
-
cargo: array of string要安装的 Rust 包
-
gem: array of string要安装的 Ruby 包
-
go: array of string要安装的 Go 包
-
npm: array of string要安装的 Node.js 包
-
pip: array of string要安装的 Python 包
-
type: optional "packages"包配置类型
"packages"
-
-
type: "cloud"环境类型
"cloud"
-
-
BetaSelfHostedConfig object { type }自托管环境的配置。
-
type: "self_hosted"环境类型
"self_hosted"
-
-
-
created_at: string环境创建时的 RFC 3339 时间戳
-
description: string用户提供的环境描述
-
metadata: map[string]用户提供的元数据键值对
-
name: string环境的可读名称
-
type: "environment"对象类型(始终为 'environment')
"environment"
-
updated_at: string环境最后更新时的 RFC 3339 时间戳
-
scope: optional "organization" or "account"此环境的可见范围。'organization' 表示对所有账户可见。'account' 表示仅对拥有账户可见。
-
"organization" -
"account"
-
-
Example
curl https://api.anthropic.com/v1/environments/$ENVIRONMENT_ID \
-H 'Content-Type: application/json' \
-H 'anthropic-version: 2023-06-01' \
-H 'anthropic-beta: managed-agents-2026-04-01' \
-H "X-Api-Key: $ANTHROPIC_API_KEY" \
-d '{
"description": "Python environment with data-analysis packages."
}'
Response
{
"id": "env_011CZkZ9X2dpNyB7HsEFoRfW",
"archived_at": null,
"config": {
"networking": {
"allow_mcp_servers": false,
"allow_package_managers": true,
"allowed_hosts": [
"api.example.com"
],
"type": "limited"
},
"packages": {
"apt": [
"string"
],
"cargo": [
"string"
],
"gem": [
"string"
],
"go": [
"string"
],
"npm": [
"string"
],
"pip": [
"pandas",
"numpy"
],
"type": "packages"
},
"type": "cloud"
},
"created_at": "2026-03-15T10:00:00Z",
"description": "Python environment with data-analysis packages.",
"metadata": {},
"name": "python-data-analysis",
"type": "environment",
"updated_at": "2026-03-15T10:00:00Z",
"scope": "organization"
}
Delete Environment
delete /v1/environments/{environment_id}
通过 ID 删除环境。返回删除确认。
Path Parameters
environment_id: string
Header Parameters
-
"anthropic-beta": optional array of AnthropicBeta可选的请求头,用于指定要使用的 beta 版本。
-
string -
"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 22 more-
"message-batches-2024-09-24" -
"prompt-caching-2024-07-31" -
"computer-use-2024-10-22" -
"computer-use-2025-01-24" -
"pdfs-2024-09-25" -
"token-counting-2024-11-01" -
"token-efficient-tools-2025-02-19" -
"output-128k-2025-02-19" -
"files-api-2025-04-14" -
"mcp-client-2025-04-04" -
"mcp-client-2025-11-20" -
"dev-full-thinking-2025-05-14" -
"interleaved-thinking-2025-05-14" -
"code-execution-2025-05-22" -
"extended-cache-ttl-2025-04-11" -
"context-1m-2025-08-07" -
"context-management-2025-06-27" -
"model-context-window-exceeded-2025-08-26" -
"skills-2025-10-02" -
"fast-mode-2026-02-01" -
"output-300k-2026-03-24" -
"user-profiles-2026-03-24" -
"advisor-tool-2026-03-01" -
"managed-agents-2026-04-01" -
"cache-diagnosis-2026-04-07"
-
-
Returns
-
BetaEnvironmentDeleteResponse object { id, type }删除环境后的响应。
-
id: string环境标识符
-
type: "environment_deleted"响应类型
"environment_deleted"
-
Example
curl https://api.anthropic.com/v1/environments/$ENVIRONMENT_ID \
-X DELETE \
-H 'anthropic-version: 2023-06-01' \
-H 'anthropic-beta: managed-agents-2026-04-01' \
-H "X-Api-Key: $ANTHROPIC_API_KEY"
Response
{
"id": "env_011CZkZ9X2dpNyB7HsEFoRfW",
"type": "environment_deleted"
}
Archive Environment
post /v1/environments/{environment_id}/archive
通过 ID 归档环境。已归档的环境不能用于创建新会话。
Path Parameters
environment_id: string
Header Parameters
-
"anthropic-beta": optional array of AnthropicBeta可选的请求头,用于指定要使用的 beta 版本。
-
string -
"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 22 more-
"message-batches-2024-09-24" -
"prompt-caching-2024-07-31" -
"computer-use-2024-10-22" -
"computer-use-2025-01-24" -
"pdfs-2024-09-25" -
"token-counting-2024-11-01" -
"token-efficient-tools-2025-02-19" -
"output-128k-2025-02-19" -
"files-api-2025-04-14" -
"mcp-client-2025-04-04" -
"mcp-client-2025-11-20" -
"dev-full-thinking-2025-05-14" -
"interleaved-thinking-2025-05-14" -
"code-execution-2025-05-22" -
"extended-cache-ttl-2025-04-11" -
"context-1m-2025-08-07" -
"context-management-2025-06-27" -
"model-context-window-exceeded-2025-08-26" -
"skills-2025-10-02" -
"fast-mode-2026-02-01" -
"output-300k-2026-03-24" -
"user-profiles-2026-03-24" -
"advisor-tool-2026-03-01" -
"managed-agents-2026-04-01" -
"cache-diagnosis-2026-04-07"
-
-
Returns
-
BetaEnvironment object { id, archived_at, config, 7 more }用于云环境和自托管环境的统一环境资源。
-
id: string环境标识符(例如 'env_...')
-
archived_at: string环境归档时的 RFC 3339 时间戳,如果未归档则为 null
-
config: BetaCloudConfig or BetaSelfHostedConfig环境配置(Anthropic Cloud 或自托管)
-
BetaCloudConfig object { networking, packages, type }cloud环境配置。-
networking: BetaUnrestrictedNetwork or BetaLimitedNetwork网络配置策略。
-
BetaUnrestrictedNetwork object { type }无限制的网络访问。
-
type: "unrestricted"网络策略类型
"unrestricted"
-
-
BetaLimitedNetwork object { allow_mcp_servers, allow_package_managers, allowed_hosts, type }有限的网络访问。
-
allow_mcp_servers: boolean允许出站访问代理上配置的 MCP 服务器端点,超出
allowed_hosts数组中列出的范围。 -
allow_package_managers: boolean允许出站访问公共包注册中心(PyPI、npm 等),超出
allowed_hosts数组中列出的范围。 -
allowed_hosts: array of string指定容器可以访问的域名。
-
type: "limited"网络策略类型
"limited"
-
-
-
packages: BetaPackages包管理器配置。
-
apt: array of string要安装的 Ubuntu/Debian 包
-
cargo: array of string要安装的 Rust 包
-
gem: array of string要安装的 Ruby 包
-
go: array of string要安装的 Go 包
-
npm: array of string要安装的 Node.js 包
-
pip: array of string要安装的 Python 包
-
type: optional "packages"包配置类型
"packages"
-
-
type: "cloud"环境类型
"cloud"
-
-
BetaSelfHostedConfig object { type }自托管环境的配置。
-
type: "self_hosted"环境类型
"self_hosted"
-
-
-
created_at: string环境创建时的 RFC 3339 时间戳
-
description: string用户提供的环境描述
-
metadata: map[string]用户提供的元数据键值对
-
name: string环境的可读名称
-
type: "environment"对象类型(始终为 'environment')
"environment"
-
updated_at: string环境最后更新时的 RFC 3339 时间戳
-
scope: optional "organization" or "account"此环境的可见范围。'organization' 表示对所有账户可见。'account' 表示仅对拥有账户可见。
-
"organization" -
"account"
-
-
Example
curl https://api.anthropic.com/v1/environments/$ENVIRONMENT_ID/archive \
-X POST \
-H 'anthropic-version: 2023-06-01' \
-H 'anthropic-beta: managed-agents-2026-04-01' \
-H "X-Api-Key: $ANTHROPIC_API_KEY"
Response
{
"id": "env_011CZkZ9X2dpNyB7HsEFoRfW",
"archived_at": null,
"config": {
"networking": {
"allow_mcp_servers": false,
"allow_package_managers": true,
"allowed_hosts": [
"api.example.com"
],
"type": "limited"
},
"packages": {
"apt": [
"string"
],
"cargo": [
"string"
],
"gem": [
"string"
],
"go": [
"string"
],
"npm": [
"string"
],
"pip": [
"pandas",
"numpy"
],
"type": "packages"
},
"type": "cloud"
},
"created_at": "2026-03-15T10:00:00Z",
"description": "Python environment with data-analysis packages.",
"metadata": {},
"name": "python-data-analysis",
"type": "environment",
"updated_at": "2026-03-15T10:00:00Z",
"scope": "organization"
}
Domain Types
Beta Cloud Config
-
BetaCloudConfig object { networking, packages, type }cloud环境配置。-
networking: BetaUnrestrictedNetwork or BetaLimitedNetwork网络配置策略。
-
BetaUnrestrictedNetwork object { type }无限制的网络访问。
-
type: "unrestricted"网络策略类型
"unrestricted"
-
-
BetaLimitedNetwork object { allow_mcp_servers, allow_package_managers, allowed_hosts, type }有限的网络访问。
-
allow_mcp_servers: boolean允许出站访问代理上配置的 MCP 服务器端点,超出
allowed_hosts数组中列出的范围。 -
allow_package_managers: boolean允许出站访问公共包注册中心(PyPI、npm 等),超出
allowed_hosts数组中列出的范围。 -
allowed_hosts: array of string指定容器可以访问的域名。
-
type: "limited"网络策略类型
"limited"
-
-
-
packages: BetaPackages包管理器配置。
-
apt: array of string要安装的 Ubuntu/Debian 包
-
cargo: array of string要安装的 Rust 包
-
gem: array of string要安装的 Ruby 包
-
go: array of string要安装的 Go 包
-
npm: array of string要安装的 Node.js 包
-
pip: array of string要安装的 Python 包
-
type: optional "packages"包配置类型
"packages"
-
-
type: "cloud"环境类型
"cloud"
-
Beta Cloud Config Params
-
BetaCloudConfigParams object { type, networking, packages }cloud环境配置的请求参数。字段默认为 null;更新时,省略的字段将保留现有值。
-
type: "cloud"环境类型
"cloud"
-
networking: optional BetaUnrestrictedNetwork or BetaLimitedNetworkParams网络配置策略。更新时省略可保留现有值。
-
BetaUnrestrictedNetwork object { type }无限制的网络访问。
-
type: "unrestricted"网络策略类型
"unrestricted"
-
-
BetaLimitedNetworkParams object { type, allow_mcp_servers, allow_package_managers, allowed_hosts }有限网络请求参数。
字段默认为 null;更新时,省略的字段将保留现有值。
-
type: "limited"网络策略类型
"limited"
-
allow_mcp_servers: optional boolean允许出站访问代理上配置的 MCP 服务器端点,超出
allowed_hosts数组中列出的范围。默认为false。 -
allow_package_managers: optional boolean允许出站访问公共包注册中心(PyPI、npm 等),超出
allowed_hosts数组中列出的范围。默认为false。 -
allowed_hosts: optional array of string指定容器可以访问的域名。
-
-
-
packages: optional BetaPackagesParams指定此环境中可用的包(可选版本)。
使用版本号时,请使用与包管理器相关的版本语义,例如对于
pip使用package==1.0.0。您需要自行验证包和版本是否存在。不指定版本将安装最新版本。-
apt: optional array of string要安装的 Ubuntu/Debian 包
-
cargo: optional array of string要安装的 Rust 包
-
gem: optional array of string要安装的 Ruby 包
-
go: optional array of string要安装的 Go 包
-
npm: optional array of string要安装的 Node.js 包
-
pip: optional array of string要安装的 Python 包
-
type: optional "packages"包配置类型
"packages"
-
-
Beta Environment
-
BetaEnvironment object { id, archived_at, config, 7 more }用于云环境和自托管环境的统一环境资源。
-
id: string环境标识符(例如 'env_...')
-
archived_at: string环境归档时的 RFC 3339 时间戳,如果未归档则为 null
-
config: BetaCloudConfig or BetaSelfHostedConfig环境配置(Anthropic Cloud 或自托管)
-
BetaCloudConfig object { networking, packages, type }cloud环境配置。-
networking: BetaUnrestrictedNetwork or BetaLimitedNetwork网络配置策略。
-
BetaUnrestrictedNetwork object { type }无限制的网络访问。
-
type: "unrestricted"网络策略类型
"unrestricted"
-
-
BetaLimitedNetwork object { allow_mcp_servers, allow_package_managers, allowed_hosts, type }有限的网络访问。
-
allow_mcp_servers: boolean允许出站访问代理上配置的 MCP 服务器端点,超出
allowed_hosts数组中列出的范围。 -
allow_package_managers: boolean允许出站访问公共包注册中心(PyPI、npm 等),超出
allowed_hosts数组中列出的范围。 -
allowed_hosts: array of string指定容器可以访问的域名。
-
type: "limited"网络策略类型
"limited"
-
-
-
packages: BetaPackages包管理器配置。
-
apt: array of string要安装的 Ubuntu/Debian 包
-
cargo: array of string要安装的 Rust 包
-
gem: array of string要安装的 Ruby 包
-
go: array of string要安装的 Go 包
-
npm: array of string要安装的 Node.js 包
-
pip: array of string要安装的 Python 包
-
type: optional "packages"包配置类型
"packages"
-
-
type: "cloud"环境类型
"cloud"
-
-
BetaSelfHostedConfig object { type }自托管环境的配置。
-
type: "self_hosted"环境类型
"self_hosted"
-
-
-
created_at: string环境创建时的 RFC 3339 时间戳
-
description: string用户提供的环境描述
-
metadata: map[string]用户提供的元数据键值对
-
name: string环境的可读名称
-
type: "environment"对象类型(始终为 'environment')
"environment"
-
updated_at: string环境最后更新时的 RFC 3339 时间戳
-
scope: optional "organization" or "account"此环境的可见范围。'organization' 表示对所有账户可见。'account' 表示仅对拥有账户可见。
-
"organization" -
"account"
-
-
Beta Environment Delete Response
-
BetaEnvironmentDeleteResponse object { id, type }删除环境后的响应。
-
id: string环境标识符
-
type: "environment_deleted"响应类型
"environment_deleted"
-
Beta Limited Network
-
BetaLimitedNetwork object { allow_mcp_servers, allow_package_managers, allowed_hosts, type }有限的网络访问。
-
allow_mcp_servers: boolean允许出站访问代理上配置的 MCP 服务器端点,超出
allowed_hosts数组中列出的范围。 -
allow_package_managers: boolean允许出站访问公共包注册中心(PyPI、npm 等),超出
allowed_hosts数组中列出的范围。 -
allowed_hosts: array of string指定容器可以访问的域名。
-
type: "limited"网络策略类型
"limited"
-
Beta Limited Network Params
-
BetaLimitedNetworkParams object { type, allow_mcp_servers, allow_package_managers, allowed_hosts }有限网络请求参数。
字段默认为 null;更新时,省略的字段将保留现有值。
-
type: "limited"网络策略类型
"limited"
-
allow_mcp_servers: optional boolean允许出站访问代理上配置的 MCP 服务器端点,超出
allowed_hosts数组中列出的范围。默认为false。 -
allow_package_managers: optional boolean允许出站访问公共包注册中心(PyPI、npm 等),超出
allowed_hosts数组中列出的范围。默认为false。 -
allowed_hosts: optional array of string指定容器可以访问的域名。
-
Beta Packages
-
BetaPackages object { apt, cargo, gem, 4 more }此环境中可用的包(及其版本)。
-
apt: array of string要安装的 Ubuntu/Debian 包
-
cargo: array of string要安装的 Rust 包
-
gem: array of string要安装的 Ruby 包
-
go: array of string要安装的 Go 包
-
npm: array of string要安装的 Node.js 包
-
pip: array of string要安装的 Python 包
-
type: optional "packages"包配置类型
"packages"
-
Beta Packages Params
-
BetaPackagesParams object { apt, cargo, gem, 4 more }指定此环境中可用的包(可选版本)。
使用版本号时,请使用与包管理器相关的版本语义,例如对于
pip使用package==1.0.0。您需要自行验证包和版本是否存在。不指定版本将安装最新版本。-
apt: optional array of string要安装的 Ubuntu/Debian 包
-
cargo: optional array of string要安装的 Rust 包
-
gem: optional array of string要安装的 Ruby 包
-
go: optional array of string要安装的 Go 包
-
npm: optional array of string要安装的 Node.js 包
-
pip: optional array of string要安装的 Python 包
-
type: optional "packages"包配置类型
"packages"
-
Beta Self Hosted Config
-
BetaSelfHostedConfig object { type }自托管环境的配置。
-
type: "self_hosted"环境类型
"self_hosted"
-
Beta Self Hosted Config Params
-
BetaSelfHostedConfigParams object { type }self_hosted环境配置的请求参数。-
type: "self_hosted"环境类型
"self_hosted"
-
Beta Unrestricted Network
-
BetaUnrestrictedNetwork object { type }无限制的网络访问。
-
type: "unrestricted"网络策略类型
"unrestricted"
-
Work
Get Work Item
get /v1/environments/{environment_id}/work/{work_id}
注意:这些端点由 SDK 和 CLI 中提供的预构建环境工作者自动调用,用于编排与自托管沙箱环境的会话。此处仅作为参考包含;您无需直接调用它们。
获取特定工作项的详细信息。
Path Parameters
-
environment_id: string -
work_id: string
Header Parameters
-
"anthropic-beta": optional array of AnthropicBeta可选的请求头,用于指定要使用的 beta 版本。
-
string -
"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 22 more-
"message-batches-2024-09-24" -
"prompt-caching-2024-07-31" -
"computer-use-2024-10-22" -
"computer-use-2025-01-24" -
"pdfs-2024-09-25" -
"token-counting-2024-11-01" -
"token-efficient-tools-2025-02-19" -
"output-128k-2025-02-19" -
"files-api-2025-04-14" -
"mcp-client-2025-04-04" -
"mcp-client-2025-11-20" -
"dev-full-thinking-2025-05-14" -
"interleaved-thinking-2025-05-14" -
"code-execution-2025-05-22" -
"extended-cache-ttl-2025-04-11" -
"context-1m-2025-08-07" -
"context-management-2025-06-27" -
"model-context-window-exceeded-2025-08-26" -
"skills-2025-10-02" -
"fast-mode-2026-02-01" -
"output-300k-2026-03-24" -
"user-profiles-2026-03-24" -
"advisor-tool-2026-03-01" -
"managed-agents-2026-04-01" -
"cache-diagnosis-2026-04-07"
-
-
Returns
-
BetaSelfHostedWork object { id, acknowledged_at, created_at, 9 more }表示自托管环境中工作单元的工作资源。
工作项在会话创建时或长期休眠的会话接收到新消息时排队。环境工作者轮询工作以在自托管沙箱中执行。
-
id: string工作标识符(例如 'work_...')
-
acknowledged_at: string工作项被确认并分配给自托管沙箱时的 RFC 3339 时间戳
-
created_at: string工作创建时的 RFC 3339 时间戳
-
data: BetaSessionWorkData要执行的实际工作
-
id: string会话标识符(例如 'session_...')
-
type: "session"工作数据类型
"session"
-
-
environment_id: string此工作所属的环境标识符(例如
env_...) -
latest_heartbeat_at: string最近一次心跳的 RFC 3339 时间戳
-
metadata: map[string]与此工作项关联的用户提供的元数据键值对
-
started_at: string工作执行开始时的 RFC 3339 时间戳
-
state: "queued" or "starting" or "active" or 2 more工作项的当前状态
-
"queued" -
"starting" -
"active" -
"stopping" -
"stopped"
-
-
stop_requested_at: string请求停止时的 RFC 3339 时间戳
-
stopped_at: string工作执行停止时的 RFC 3339 时间戳
-
type: "work"对象类型(始终为 'work')
"work"
-
Example
curl https://api.anthropic.com/v1/environments/$ENVIRONMENT_ID/work/$WORK_ID \
-H 'anthropic-version: 2023-06-01' \
-H 'anthropic-beta: managed-agents-2026-04-01' \
-H "X-Api-Key: $ANTHROPIC_API_KEY"
Response
{
"id": "id",
"acknowledged_at": "acknowledged_at",
"created_at": "created_at",
"data": {
"id": "id",
"type": "session"
},
"environment_id": "environment_id",
"latest_heartbeat_at": "latest_heartbeat_at",
"metadata": {
"foo": "string"
},
"started_at": "started_at",
"state": "queued",
"stop_requested_at": "stop_requested_at",
"stopped_at": "stopped_at",
"type": "work"
}
Poll for Work
get /v1/environments/{environment_id}/work/poll
注意:这些端点由 SDK 和 CLI 中提供的预构建环境工作者自动调用,用于编排与自托管沙箱环境的会话。此处仅作为参考包含;您无需直接调用它们。
长轮询队列中的工作项。
Path Parameters
environment_id: string
Query Parameters
-
block_ms: optional number返回前等待工作到达的时间。必须为 1-999 毫秒。默认为非阻塞(如果没有可用工作则立即返回)。
-
reclaim_older_than_ms: optional number回收超过此毫秒数的未确认工作项。如果省略,使用默认值(5000ms)。
Header Parameters
-
"anthropic-beta": optional array of AnthropicBeta可选的请求头,用于指定要使用的 beta 版本。
-
string -
"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 22 more-
"message-batches-2024-09-24" -
"prompt-caching-2024-07-31" -
"computer-use-2024-10-22" -
"computer-use-2025-01-24" -
"pdfs-2024-09-25" -
"token-counting-2024-11-01" -
"token-efficient-tools-2025-02-19" -
"output-128k-2025-02-19" -
"files-api-2025-04-14" -
"mcp-client-2025-04-04" -
"mcp-client-2025-11-20" -
"dev-full-thinking-2025-05-14" -
"interleaved-thinking-2025-05-14" -
"code-execution-2025-05-22" -
"extended-cache-ttl-2025-04-11" -
"context-1m-2025-08-07" -
"context-management-2025-06-27" -
"model-context-window-exceeded-2025-08-26" -
"skills-2025-10-02" -
"fast-mode-2026-02-01" -
"output-300k-2026-03-24" -
"user-profiles-2026-03-24" -
"advisor-tool-2026-03-01" -
"managed-agents-2026-04-01" -
"cache-diagnosis-2026-04-07"
-
-
-
"Anthropic-Worker-ID": optional string特定轮询工作者的唯一标识符,用于在控制台中跟踪聚合的环境级工作指标
Returns
-
BetaSelfHostedWork object { id, acknowledged_at, created_at, 9 more }表示自托管环境中工作单元的工作资源。
工作项在会话创建时或长期休眠的会话接收到新消息时排队。环境工作者轮询工作以在自托管沙箱中执行。
-
id: string工作标识符(例如 'work_...')
-
acknowledged_at: string工作项被确认并分配给自托管沙箱时的 RFC 3339 时间戳
-
created_at: string工作创建时的 RFC 3339 时间戳
-
data: BetaSessionWorkData要执行的实际工作
-
id: string会话标识符(例如 'session_...')
-
type: "session"工作数据类型
"session"
-
-
environment_id: string此工作所属的环境标识符(例如
env_...) -
latest_heartbeat_at: string最近一次心跳的 RFC 3339 时间戳
-
metadata: map[string]与此工作项关联的用户提供的元数据键值对
-
started_at: string工作执行开始时的 RFC 3339 时间戳
-
state: "queued" or "starting" or "active" or 2 more工作项的当前状态
-
"queued" -
"starting" -
"active" -
"stopping" -
"stopped"
-
-
stop_requested_at: string请求停止时的 RFC 3339 时间戳
-
stopped_at: string工作执行停止时的 RFC 3339 时间戳
-
type: "work"对象类型(始终为 'work')
"work"
-
Example
curl https://api.anthropic.com/v1/environments/$ENVIRONMENT_ID/work/poll \
-H 'anthropic-version: 2023-06-01' \
-H 'anthropic-beta: managed-agents-2026-04-01' \
-H "X-Api-Key: $ANTHROPIC_API_KEY"
Response
{
"id": "id",
"acknowledged_at": "acknowledged_at",
"created_at": "created_at",
"data": {
"id": "id",
"type": "session"
},
"environment_id": "environment_id",
"latest_heartbeat_at": "latest_heartbeat_at",
"metadata": {
"foo": "string"
},
"started_at": "started_at",
"state": "queued",
"stop_requested_at": "stop_requested_at",
"stopped_at": "stopped_at",
"type": "work"
}
Acknowledge Work
post /v1/environments/{environment_id}/work/{work_id}/ack
注意:这些端点由 SDK 和 CLI 中提供的预构建环境工作者自动调用,用于编排与自托管沙箱环境的会话。此处仅作为参考包含;您无需直接调用它们。
确认收到工作项,将其从 'queued' 转换为 'starting' 并从队列中移除。
Path Parameters
-
environment_id: string -
work_id: string
Header Parameters
-
"anthropic-beta": optional array of AnthropicBeta可选的请求头,用于指定要使用的 beta 版本。
-
string -
"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 22 more-
"message-batches-2024-09-24" -
"prompt-caching-2024-07-31" -
"computer-use-2024-10-22" -
"computer-use-2025-01-24" -
"pdfs-2024-09-25" -
"token-counting-2024-11-01" -
"token-efficient-tools-2025-02-19" -
"output-128k-2025-02-19" -
"files-api-2025-04-14" -
"mcp-client-2025-04-04" -
"mcp-client-2025-11-20" -
"dev-full-thinking-2025-05-14" -
"interleaved-thinking-2025-05-14" -
"code-execution-2025-05-22" -
"extended-cache-ttl-2025-04-11" -
"context-1m-2025-08-07" -
"context-management-2025-06-27" -
"model-context-window-exceeded-2025-08-26" -
"skills-2025-10-02" -
"fast-mode-2026-02-01" -
"output-300k-2026-03-24" -
"user-profiles-2026-03-24" -
"advisor-tool-2026-03-01" -
"managed-agents-2026-04-01" -
"cache-diagnosis-2026-04-07"
-
-
Returns
-
BetaSelfHostedWork object { id, acknowledged_at, created_at, 9 more }表示自托管环境中工作单元的工作资源。
工作项在会话创建时或长期休眠的会话接收到新消息时排队。环境工作者轮询工作以在自托管沙箱中执行。
-
id: string工作标识符(例如 'work_...')
-
acknowledged_at: string工作项被确认并分配给自托管沙箱时的 RFC 3339 时间戳
-
created_at: string工作创建时的 RFC 3339 时间戳
-
data: BetaSessionWorkData要执行的实际工作
-
id: string会话标识符(例如 'session_...')
-
type: "session"工作数据类型
"session"
-
-
environment_id: string此工作所属的环境标识符(例如
env_...) -
latest_heartbeat_at: string最近一次心跳的 RFC 3339 时间戳
-
metadata: map[string]与此工作项关联的用户提供的元数据键值对
-
started_at: string工作执行开始时的 RFC 3339 时间戳
-
state: "queued" or "starting" or "active" or 2 more工作项的当前状态
-
"queued" -
"starting" -
"active" -
"stopping" -
"stopped"
-
-
stop_requested_at: string请求停止时的 RFC 3339 时间戳
-
stopped_at: string工作执行停止时的 RFC 3339 时间戳
-
type: "work"对象类型(始终为 'work')
"work"
-
Example
curl https://api.anthropic.com/v1/environments/$ENVIRONMENT_ID/work/$WORK_ID/ack \
-X POST \
-H 'anthropic-version: 2023-06-01' \
-H 'anthropic-beta: managed-agents-2026-04-01' \
-H "X-Api-Key: $ANTHROPIC_API_KEY"
Response
{
"id": "id",
"acknowledged_at": "acknowledged_at",
"created_at": "created_at",
"data": {
"id": "id",
"type": "session"
},
"environment_id": "environment_id",
"latest_heartbeat_at": "latest_heartbeat_at",
"metadata": {
"foo": "string"
},
"started_at": "started_at",
"state": "queued",
"stop_requested_at": "stop_requested_at",
"stopped_at": "stopped_at",
"type": "work"
}
Record Heartbeat
post /v1/environments/{environment_id}/work/{work_id}/heartbeat
注意:这些端点由 SDK 和 CLI 中提供的预构建环境工作者自动调用,用于编排与自托管沙箱环境的会话。此处仅作为参考包含;您无需直接调用它们。
记录工作项的心跳以维持租约。
Path Parameters
-
environment_id: string -
work_id: string
Query Parameters
-
desired_ttl_seconds: optional number期望的 TTL(秒)
-
expected_last_heartbeat: optional string用于条件更新(乐观并发)的期望 last_heartbeat。使用字面量 'NO_HEARTBEAT' 来声明未认领的租约(首次心跳)。对于后续心跳,请完全回显服务器之前的 last_heartbeat 值。如果实际值不匹配,返回 412 Precondition Failed。
Header Parameters
-
"anthropic-beta": optional array of AnthropicBeta可选的请求头,用于指定要使用的 beta 版本。
-
string -
"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 22 more-
"message-batches-2024-09-24" -
"prompt-caching-2024-07-31" -
"computer-use-2024-10-22" -
"computer-use-2025-01-24" -
"pdfs-2024-09-25" -
"token-counting-2024-11-01" -
"token-efficient-tools-2025-02-19" -
"output-128k-2025-02-19" -
"files-api-2025-04-14" -
"mcp-client-2025-04-04" -
"mcp-client-2025-11-20" -
"dev-full-thinking-2025-05-14" -
"interleaved-thinking-2025-05-14" -
"code-execution-2025-05-22" -
"extended-cache-ttl-2025-04-11" -
"context-1m-2025-08-07" -
"context-management-2025-06-27" -
"model-context-window-exceeded-2025-08-26" -
"skills-2025-10-02" -
"fast-mode-2026-02-01" -
"output-300k-2026-03-24" -
"user-profiles-2026-03-24" -
"advisor-tool-2026-03-01" -
"managed-agents-2026-04-01" -
"cache-diagnosis-2026-04-07"
-
-
Returns
-
BetaSelfHostedWorkHeartbeatResponse object { last_heartbeat, lease_extended, state, 2 more }记录工作项心跳后的响应。
-
last_heartbeat: string来自数据库的实际心跳的 RFC 3339 时间戳
-
lease_extended: boolean心跳是否成功延长了租约
-
state: "queued" or "starting" or "active" or 2 more工作项的当前状态(active/stopping/stopped)
-
"queued" -
"starting" -
"active" -
"stopping" -
"stopped"
-
-
ttl_seconds: number应用于租约的有效 TTL
-
type: "work_heartbeat"响应类型
"work_heartbeat"
-
Example
curl https://api.anthropic.com/v1/environments/$ENVIRONMENT_ID/work/$WORK_ID/heartbeat \
-X POST \
-H 'anthropic-version: 2023-06-01' \
-H 'anthropic-beta: managed-agents-2026-04-01' \
-H "X-Api-Key: $ANTHROPIC_API_KEY"
Response
{
"last_heartbeat": "last_heartbeat",
"lease_extended": true,
"state": "queued",
"ttl_seconds": 0,
"type": "work_heartbeat"
}
Stop Work
post /v1/environments/{environment_id}/work/{work_id}/stop
注意:这些端点由 SDK 和 CLI 中提供的预构建环境工作者自动调用,用于编排与自托管沙箱环境的会话。此处仅作为参考包含;您无需直接调用它们。
停止工作项,启动优雅或强制关闭。
Path Parameters
-
environment_id: string -
work_id: string
Header Parameters
-
"anthropic-beta": optional array of AnthropicBeta可选的请求头,用于指定要使用的 beta 版本。
-
string -
"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 22 more-
"message-batches-2024-09-24" -
"prompt-caching-2024-07-31" -
"computer-use-2024-10-22" -
"computer-use-2025-01-24" -
"pdfs-2024-09-25" -
"token-counting-2024-11-01" -
"token-efficient-tools-2025-02-19" -
"output-128k-2025-02-19" -
"files-api-2025-04-14" -
"mcp-client-2025-04-04" -
"mcp-client-2025-11-20" -
"dev-full-thinking-2025-05-14" -
"interleaved-thinking-2025-05-14" -
"code-execution-2025-05-22" -
"extended-cache-ttl-2025-04-11" -
"context-1m-2025-08-07" -
"context-management-2025-06-27" -
"model-context-window-exceeded-2025-08-26" -
"skills-2025-10-02" -
"fast-mode-2026-02-01" -
"output-300k-2026-03-24" -
"user-profiles-2026-03-24" -
"advisor-tool-2026-03-01" -
"managed-agents-2026-04-01" -
"cache-diagnosis-2026-04-07"
-
-
Body Parameters
-
force: optional boolean如果为 true,立即停止工作而不进行优雅关闭
Returns
-
BetaSelfHostedWork object { id, acknowledged_at, created_at, 9 more }表示自托管环境中工作单元的工作资源。
工作项在会话创建时或长期休眠的会话接收到新消息时排队。环境工作者轮询工作以在自托管沙箱中执行。
-
id: string工作标识符(例如 'work_...')
-
acknowledged_at: string工作项被确认并分配给自托管沙箱时的 RFC 3339 时间戳
-
created_at: string工作创建时的 RFC 3339 时间戳
-
data: BetaSessionWorkData要执行的实际工作
-
id: string会话标识符(例如 'session_...')
-
type: "session"工作数据类型
"session"
-
-
environment_id: string此工作所属的环境标识符(例如
env_...) -
latest_heartbeat_at: string最近一次心跳的 RFC 3339 时间戳
-
metadata: map[string]与此工作项关联的用户提供的元数据键值对
-
started_at: string工作执行开始时的 RFC 3339 时间戳
-
state: "queued" or "starting" or "active" or 2 more工作项的当前状态
-
"queued" -
"starting" -
"active" -
"stopping" -
"stopped"
-
-
stop_requested_at: string请求停止时的 RFC 3339 时间戳
-
stopped_at: string工作执行停止时的 RFC 3339 时间戳
-
type: "work"对象类型(始终为 'work')
"work"
-
Example
curl https://api.anthropic.com/v1/environments/$ENVIRONMENT_ID/work/$WORK_ID/stop \
-H 'Content-Type: application/json' \
-H 'anthropic-version: 2023-06-01' \
-H 'anthropic-beta: managed-agents-2026-04-01' \
-H "X-Api-Key: $ANTHROPIC_API_KEY" \
-d '{}'
Response
{
"id": "id",
"acknowledged_at": "acknowledged_at",
"created_at": "created_at",
"data": {
"id": "id",
"type": "session"
},
"environment_id": "environment_id",
"latest_heartbeat_at": "latest_heartbeat_at",
"metadata": {
"foo": "string"
},
"started_at": "started_at",
"state": "queued",
"stop_requested_at": "stop_requested_at",
"stopped_at": "stopped_at",
"type": "work"
}
List Work Items
get /v1/environments/{environment_id}/work
注意:这些端点由 SDK 和 CLI 中提供的预构建环境工作者自动调用,用于编排与自托管沙箱环境的会话。此处仅作为参考包含;您无需直接调用它们。
列出环境中的工作项。
Path Parameters
environment_id: string
Query Parameters
-
limit: optional number返回的最大工作项数量
-
page: optional string用于分页的上一个响应中的不透明游标
Header Parameters
-
"anthropic-beta": optional array of AnthropicBeta可选的请求头,用于指定要使用的 beta 版本。
-
string -
"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 22 more-
"message-batches-2024-09-24" -
"prompt-caching-2024-07-31" -
"computer-use-2024-10-22" -
"computer-use-2025-01-24" -
"pdfs-2024-09-25" -
"token-counting-2024-11-01" -
"token-efficient-tools-2025-02-19" -
"output-128k-2025-02-19" -
"files-api-2025-04-14" -
"mcp-client-2025-04-04" -
"mcp-client-2025-11-20" -
"dev-full-thinking-2025-05-14" -
"interleaved-thinking-2025-05-14" -
"code-execution-2025-05-22" -
"extended-cache-ttl-2025-04-11" -
"context-1m-2025-08-07" -
"context-management-2025-06-27" -
"model-context-window-exceeded-2025-08-26" -
"skills-2025-10-02" -
"fast-mode-2026-02-01" -
"output-300k-2026-03-24" -
"user-profiles-2026-03-24" -
"advisor-tool-2026-03-01" -
"managed-agents-2026-04-01" -
"cache-diagnosis-2026-04-07"
-
-
Returns
-
BetaSelfHostedWorkListResponse object { data, next_page }使用游标分页列出工作项时的响应。
-
data: array of BetaSelfHostedWork工作项列表
-
id: string工作标识符(例如 'work_...')
-
acknowledged_at: string工作项被确认并分配给自托管沙箱时的 RFC 3339 时间戳
-
created_at: string工作创建时的 RFC 3339 时间戳
-
data: BetaSessionWorkData要执行的实际工作
-
id: string会话标识符(例如 'session_...')
-
type: "session"工作数据类型
"session"
-
-
environment_id: string此工作所属的环境标识符(例如
env_...) -
latest_heartbeat_at: string最近一次心跳的 RFC 3339 时间戳
-
metadata: map[string]与此工作项关联的用户提供的元数据键值对
-
started_at: string工作执行开始时的 RFC 3339 时间戳
-
state: "queued" or "starting" or "active" or 2 more工作项的当前状态
-
"queued" -
"starting" -
"active" -
"stopping" -
"stopped"
-
-
stop_requested_at: string请求停止时的 RFC 3339 时间戳
-
stopped_at: string工作执行停止时的 RFC 3339 时间戳
-
type: "work"对象类型(始终为 'work')
"work"
-
-
next_page: string用于获取下一页结果的不透明游标
-
Example
curl https://api.anthropic.com/v1/environments/$ENVIRONMENT_ID/work \
-H 'anthropic-version: 2023-06-01' \
-H 'anthropic-beta: managed-agents-2026-04-01' \
-H "X-Api-Key: $ANTHROPIC_API_KEY"
Response
{
"data": [
{
"id": "id",
"acknowledged_at": "acknowledged_at",
"created_at": "created_at",
"data": {
"id": "id",
"type": "session"
},
"environment_id": "environment_id",
"latest_heartbeat_at": "latest_heartbeat_at",
"metadata": {
"foo": "string"
},
"started_at": "started_at",
"state": "queued",
"stop_requested_at": "stop_requested_at",
"stopped_at": "stopped_at",
"type": "work"
}
],
"next_page": "next_page"
}
Update Work Item
post /v1/environments/{environment_id}/work/{work_id}
注意:这些端点由 SDK 和 CLI 中提供的预构建环境工作者自动调用,用于编排与自托管沙箱环境的会话。此处仅作为参考包含;您无需直接调用它们。
使用合并语义更新工作项元数据。
Path Parameters
-
environment_id: string -
work_id: string
Header Parameters
-
"anthropic-beta": optional array of AnthropicBeta可选的请求头,用于指定要使用的 beta 版本。
-
string -
"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 22 more-
"message-batches-2024-09-24" -
"prompt-caching-2024-07-31" -
"computer-use-2024-10-22" -
"computer-use-2025-01-24" -
"pdfs-2024-09-25" -
"token-counting-2024-11-01" -
"token-efficient-tools-2025-02-19" -
"output-128k-2025-02-19" -
"files-api-2025-04-14" -
"mcp-client-2025-04-04" -
"mcp-client-2025-11-20" -
"dev-full-thinking-2025-05-14" -
"interleaved-thinking-2025-05-14" -
"code-execution-2025-05-22" -
"extended-cache-ttl-2025-04-11" -
"context-1m-2025-08-07" -
"context-management-2025-06-27" -
"model-context-window-exceeded-2025-08-26" -
"skills-2025-10-02" -
"fast-mode-2026-02-01" -
"output-300k-2026-03-24" -
"user-profiles-2026-03-24" -
"advisor-tool-2026-03-01" -
"managed-agents-2026-04-01" -
"cache-diagnosis-2026-04-07"
-
-
Body Parameters
-
metadata: map[string]元数据补丁。将键设置为字符串以插入或更新,设置为 null 以删除。省略该字段以保留现有元数据。
Returns
-
BetaSelfHostedWork object { id, acknowledged_at, created_at, 9 more }表示自托管环境中工作单元的工作资源。
工作项在会话创建时或长期休眠的会话接收到新消息时排队。环境工作者轮询工作以在自托管沙箱中执行。
-
id: string工作标识符(例如 'work_...')
-
acknowledged_at: string工作项被确认并分配给自托管沙箱时的 RFC 3339 时间戳
-
created_at: string工作创建时的 RFC 3339 时间戳
-
data: BetaSessionWorkData要执行的实际工作
-
id: string会话标识符(例如 'session_...')
-
type: "session"工作数据类型
"session"
-
-
environment_id: string此工作所属的环境标识符(例如
env_...) -
latest_heartbeat_at: string最近一次心跳的 RFC 3339 时间戳
-
metadata: map[string]与此工作项关联的用户提供的元数据键值对
-
started_at: string工作执行开始时的 RFC 3339 时间戳
-
state: "queued" or "starting" or "active" or 2 more工作项的当前状态
-
"queued" -
"starting" -
"active" -
"stopping" -
"stopped"
-
-
stop_requested_at: string请求停止时的 RFC 3339 时间戳
-
stopped_at: string工作执行停止时的 RFC 3339 时间戳
-
type: "work"对象类型(始终为 'work')
"work"
-
Example
curl https://api.anthropic.com/v1/environments/$ENVIRONMENT_ID/work/$WORK_ID \
-H 'Content-Type: application/json' \
-H 'anthropic-version: 2023-06-01' \
-H 'anthropic-beta: managed-agents-2026-04-01' \
-H "X-Api-Key: $ANTHROPIC_API_KEY" \
-d '{
"metadata": {
"foo": "string"
}
}'
Response
{
"id": "id",
"acknowledged_at": "acknowledged_at",
"created_at": "created_at",
"data": {
"id": "id",
"type": "session"
},
"environment_id": "environment_id",
"latest_heartbeat_at": "latest_heartbeat_at",
"metadata": {
"foo": "string"
},
"started_at": "started_at",
"state": "queued",
"stop_requested_at": "stop_requested_at",
"stopped_at": "stopped_at",
"type": "work"
}
Get Queue Statistics
get /v1/environments/{environment_id}/work/stats
获取环境工作队列的统计信息。
Path Parameters
environment_id: string
Header Parameters
-
"anthropic-beta": optional array of AnthropicBeta可选的请求头,用于指定要使用的 beta 版本。
-
string -
"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 22 more-
"message-batches-2024-09-24" -
"prompt-caching-2024-07-31" -
"computer-use-2024-10-22" -
"computer-use-2025-01-24" -
"pdfs-2024-09-25" -
"token-counting-2024-11-01" -
"token-efficient-tools-2025-02-19" -
"output-128k-2025-02-19" -
"files-api-2025-04-14" -
"mcp-client-2025-04-04" -
"mcp-client-2025-11-20" -
"dev-full-thinking-2025-05-14" -
"interleaved-thinking-2025-05-14" -
"code-execution-2025-05-22" -
"extended-cache-ttl-2025-04-11" -
"context-1m-2025-08-07" -
"context-management-2025-06-27" -
"model-context-window-exceeded-2025-08-26" -
"skills-2025-10-02" -
"fast-mode-2026-02-01" -
"output-300k-2026-03-24" -
"user-profiles-2026-03-24" -
"advisor-tool-2026-03-01" -
"managed-agents-2026-04-01" -
"cache-diagnosis-2026-04-07"
-
-
Returns
-
BetaSelfHostedWorkQueueStats object { depth, oldest_queued_at, pending, 2 more }环境工作队列的统计信息。
使用 Redis Stream 消费者组指标进行 O(1) 查询。
-
depth: number等待被拾取的工作项数量(消费者组的滞后)
-
oldest_queued_at: string工作流中最旧项的 RFC 3339 时间戳(包括排队和待处理项),如果流为空则为 null
-
pending: number正在处理的工作项数量(已轮询但未确认)
-
type: "work_queue_stats"对象类型
"work_queue_stats"
-
workers_polling: number在过去 30 秒内轮询过工作的工作器数量。需要在轮询请求中发送 worker_id。
-
Example
curl https://api.anthropic.com/v1/environments/$ENVIRONMENT_ID/work/stats \
-H 'anthropic-version: 2023-06-01' \
-H 'anthropic-beta: managed-agents-2026-04-01' \
-H "X-Api-Key: $ANTHROPIC_API_KEY"
Response
{
"depth": 0,
"oldest_queued_at": "oldest_queued_at",
"pending": 0,
"type": "work_queue_stats",
"workers_polling": 0
}
Domain Types
Beta Self Hosted Work
-
BetaSelfHostedWork object { id, acknowledged_at, created_at, 9 more }表示自托管环境中工作单元的工作资源。
工作项在会话创建时或长期休眠的会话接收到新消息时排队。环境工作者轮询工作以在自托管沙箱中执行。
-
id: string工作标识符(例如 'work_...')
-
acknowledged_at: string工作项被确认并分配给自托管沙箱时的 RFC 3339 时间戳
-
created_at: string工作创建时的 RFC 3339 时间戳
-
data: BetaSessionWorkData要执行的实际工作
-
id: string会话标识符(例如 'session_...')
-
type: "session"工作数据类型
"session"
-
-
environment_id: string此工作所属的环境标识符(例如
env_...) -
latest_heartbeat_at: string最近一次心跳的 RFC 3339 时间戳
-
metadata: map[string]与此工作项关联的用户提供的元数据键值对
-
started_at: string工作执行开始时的 RFC 3339 时间戳
-
state: "queued" or "starting" or "active" or 2 more工作项的当前状态
-
"queued" -
"starting" -
"active" -
"stopping" -
"stopped"
-
-
stop_requested_at: string请求停止时的 RFC 3339 时间戳
-
stopped_at: string工作执行停止时的 RFC 3339 时间戳
-
type: "work"对象类型(始终为 'work')
"work"
-
Beta Self Hosted Work Heartbeat Response
-
BetaSelfHostedWorkHeartbeatResponse object { last_heartbeat, lease_extended, state, 2 more }记录工作项心跳后的响应。
-
last_heartbeat: string来自数据库的实际心跳的 RFC 3339 时间戳
-
lease_extended: boolean心跳是否成功延长了租约
-
state: "queued" or "starting" or "active" or 2 more工作项的当前状态(active/stopping/stopped)
-
"queued" -
"starting" -
"active" -
"stopping" -
"stopped"
-
-
ttl_seconds: number应用于租约的有效 TTL
-
type: "work_heartbeat"响应类型
"work_heartbeat"
-
Beta Self Hosted Work List Response
-
BetaSelfHostedWorkListResponse object { data, next_page }使用游标分页列出工作项时的响应。
-
data: array of BetaSelfHostedWork工作项列表
-
id: string工作标识符(例如 'work_...')
-
acknowledged_at: string工作项被确认并分配给自托管沙箱时的 RFC 3339 时间戳
-
created_at: string工作创建时的 RFC 3339 时间戳
-
data: BetaSessionWorkData要执行的实际工作
-
id: string会话标识符(例如 'session_...')
-
type: "session"工作数据类型
"session"
-
-
environment_id: string此工作所属的环境标识符(例如
env_...) -
latest_heartbeat_at: string最近一次心跳的 RFC 3339 时间戳
-
metadata: map[string]与此工作项关联的用户提供的元数据键值对
-
started_at: string工作执行开始时的 RFC 3339 时间戳
-
state: "queued" or "starting" or "active" or 2 more工作项的当前状态
-
"queued" -
"starting" -
"active" -
"stopping" -
"stopped"
-
-
stop_requested_at: string请求停止时的 RFC 3339 时间戳
-
stopped_at: string工作执行停止时的 RFC 3339 时间戳
-
type: "work"对象类型(始终为 'work')
"work"
-
-
next_page: string用于获取下一页结果的不透明游标
-
Beta Self Hosted Work Queue Stats
-
BetaSelfHostedWorkQueueStats object { depth, oldest_queued_at, pending, 2 more }环境工作队列的统计信息。
使用 Redis Stream 消费者组指标进行 O(1) 查询。
-
depth: number等待被拾取的工作项数量(消费者组的滞后)
-
oldest_queued_at: string工作流中最旧项的 RFC 3339 时间戳(包括排队和待处理项),如果流为空则为 null
-
pending: number正在处理的工作项数量(已轮询但未确认)
-
type: "work_queue_stats"对象类型
"work_queue_stats"
-
workers_polling: number在过去 30 秒内轮询过工作的工作器数量。需要在轮询请求中发送 worker_id。
-
Beta Self Hosted Work Stop Request
-
BetaSelfHostedWorkStopRequest object { force }停止工作项的请求。
-
force: optional boolean如果为 true,立即停止工作而不进行优雅关闭
-
Beta Self Hosted Work Update Request
-
BetaSelfHostedWorkUpdateRequest object { metadata }更新工作项元数据的请求。
-
metadata: map[string]元数据补丁。将键设置为字符串以插入或更新,设置为 null 以删除。省略该字段以保留现有元数据。
-
Beta Session Work Data
-
BetaSessionWorkData object { id, type }会话工作项的工作数据。
此资源类型用于工作表示需要在自托管环境中执行的会话时。
-
id: string会话标识符(例如 'session_...')
-
type: "session"工作数据类型
"session"
-