跳转到内容
EN

更新环境

先调用「创建环境」,用返回的环境 ID 替换 env_123。

POST/agent/v1/environments/{environment_id}◐ 部分支持

请求参数

  • environment_idstring必填

    path: 环境 ID,由 environments.create 或 environments.list 返回。内置环境可读取,但不可更改。

  • namestring可选

    Updated name for the environment

  • metadataobject可选

    用户提供的元数据键值对。将值设为 null 或空字符串以删除该键。

  • configobject可选

    Updated environment configuration

    展开子字段 (4)
    • typestring必填

      环境类型:cloud 在沙箱配方里运行会话;self_hosted 不支持,返回 400。

      取值 cloudself_hosted
    • networkingobject可选

      网络配置策略。更新时省略则保留现值。type 为 self_hosted 时不使用。

    • packagesobject可选

      指定环境中可用的软件包及可选版本。指定版本时使用对应包管理器的版本语义,例如 pip 使用 package==1.0.0。你负责验证软件包和版本存在。不指定版本则安装最新版。在 limited 网络策略下,要求 networking.allow_package_managers 为 true。type 为 self_hosted 时不使用。

    • templatestring可选

      创建环境机器所用的沙箱模板:sandbox.bases.list 中公开 Base 的名称(如 base、base-large、media),或你自己的就绪沙箱 Environment 的名称或 sbe_ ID。规格由模板名称表示(如 base-large),没有单独的 size 字段。名称为 1–128 个字母、数字、下划线、点或连字符;其他值返回 400 config.template must be a sandbox template name。保存时不检查名称;沙箱不认识的模板会使机器失败,报 Environment template <name> is not available。创建时省略或传 null 则为默认 node22;更新时省略则保留。仅 /agent/v1 支持。type 为 self_hosted 时不使用。

  • descriptionstring可选

    更新后的环境说明。省略则保留;null 清除为 null;空字符串按空字符串保存。

返回

200

支持租户自建 cloud 环境、配置更新与软归档;内置环境只读。列表支持 limit、page 和 include_archived。limited 网络在沙箱创建时生效;安装失败会终止会话,错误码为 ENVIRONMENT_PACKAGE_INSTALL_FAILED。self_hosted、scope 和跨会话包缓存尚不支持。

错误按 Anthropic 错误格式返回(type / message / request_id),参见 错误码

请求示例

curl
# 先调用「创建环境」,用返回的环境 ID 替换 env_123。
curl https://api.deepraxis.com/agent/v1/environments/env_123 \
  -H "Authorization: Bearer $PRAXIS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"updated-environment"}'
Python
# 先调用「创建环境」,用返回的环境 ID 替换 env_123。
import requests

opts = dict(
    base_url="https://api.deepraxis.com/agent",
    api_key="$PRAXIS_API_KEY",
)

# /agent 是我们自己的 Managed Agents 形状,直接发 HTTP 请求(Bearer 认证)
resp = requests.post(
    f"{opts['base_url']}/v1/environments/env_123",
    headers={"Authorization": f"Bearer {opts['api_key']}"},
    json={"name":"updated-environment"},
)
print(resp.status_code, resp.json())
TypeScript
// 先调用「创建环境」,用返回的环境 ID 替换 env_123。
const opts = {
  baseURL: "https://api.deepraxis.com/agent",
  apiKey: "$PRAXIS_API_KEY",
};

// /agent 是我们自己的 Managed Agents 形状,直接发 HTTP 请求(Bearer 认证)
const resp = await fetch(`${opts.baseURL}/v1/environments/env_123`, {
  method: "POST",
  headers: { Authorization: `Bearer ${opts.apiKey}`, "Content-Type": "application/json" },
  body: JSON.stringify({"name":"updated-environment"}),
});
console.log(resp.status, await resp.json());

响应示例 200

{
  "id": "env_8010a04c445b4176964e978afa1c46d0",
  "name": "docs-k16-updated",
  "description": null,
  "created_at": "2026-10-11T10:34:48.706Z",
  "updated_at": "2026-10-11T10:34:50.287Z",
  "archived_at": null,
  "type": "environment",
  "config": {
    "type": "cloud",
    "networking": {
      "type": "unrestricted"
    },
    "packages": {
      "type": "packages",
      "apt": [],
      "pip": [],
      "npm": [],
      "cargo": [],
      "gem": [],
      "go": []
    }
  },
  "metadata": {}
}

响应

HTTP 200

Successful response

application/json

名称 类型 说明
id string Environment identifier (e.g., 'env_...')
archived_at null | string RFC 3339 timestamp when environment was archived, or null if not archived
config object Environment configuration (either Anthropic Cloud or self-hosted)
config.networking object Network configuration policy.
config.packages object Package manager configuration.
config.type string Environment type
config.template string | null Sandbox template machines of this environment are created from: a public Base name or one of your own sandbox Environments (name or sbe_ id); size is expressed by the template name. The built-in node22 shows node22; null or absent means the default node22. /agent/v1 only.
created_at string RFC 3339 timestamp when environment was created
description null | string User-provided description for the environment; null when unset
metadata object User-provided metadata key-value pairs
name string Human-readable name for the environment
type string The type of object (always 'environment')
updated_at string RFC 3339 timestamp when environment was last updated
scope string The visibility scope for this environment. 'organization' means visible to all accounts. 'account' means visible only to the owning account.