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"
}