Loading...
    • 建構
    • 管理
    • 模型與定價
    • 客戶端 SDK
    • API 參考
    Search...
    ⌘K
    第一步
    Claude 簡介快速入門
    使用 Claude 建構
    功能概覽使用 Messages API處理停止原因
    模型功能
    延伸思考自適應思考效能快速模式(測試版:研究預覽)結構化輸出引用來源串流訊息批次處理搜尋結果串流拒絕多語言支援嵌入向量
    工具
    概覽工具使用方式網路搜尋工具網路擷取工具程式碼執行工具記憶體工具Bash 工具電腦使用工具文字編輯器工具
    工具基礎架構
    工具搜尋程式化工具呼叫細粒度工具串流
    上下文管理
    上下文視窗壓縮上下文編輯提示快取Token 計數
    處理檔案
    Files APIPDF 支援圖像與視覺
    技能
    概覽快速入門最佳實踐企業版技能API 中的技能
    MCP
    遠端 MCP 伺服器MCP 連接器
    提示工程
    概覽提示最佳實踐Console 提示工具
    測試與評估
    定義成功標準並建立評估在 Console 中使用評估工具降低延遲
    強化防護欄
    減少幻覺提高輸出一致性防範越獄減少提示洩漏
    資源
    詞彙表
    版本說明
    Claude Platform
    Console
    Log in
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Partners

    • Amazon Bedrock
    • Google Cloud's Vertex AI

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Help and security

    • Availability
    • Status
    • Support
    • Discord

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy
    設定代理環境

    雲端環境設定

    為您的工作階段自訂雲端容器。

    環境定義了您的代理程式執行所在的容器配置。您建立一次環境,然後在每次啟動工作階段時參考其 ID。多個工作階段可以共享同一個環境,但每個工作階段都會獲得自己隔離的容器實例。

    所有 Managed Agents API 請求都需要 managed-agents-2026-04-01 beta 標頭。SDK 會自動設定 beta 標頭。

    建立環境

    environment=$(curl -fsS https://api.anthropic.com/v1/environments \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -H "anthropic-beta: managed-agents-2026-04-01" \
      -H "content-type: application/json" \
      --data @- <<'EOF'
    {
      "name": "python-dev",
      "config": {
        "type": "cloud",
        "networking": {"type": "unrestricted"}
      }
    }
    EOF
    )
    environment_id=$(jq -r '.id' <<< "$environment")
    
    echo "Environment ID: $environment_id"

    name 必須在您的組織和工作區內是唯一的。

    在工作階段中使用環境

    建立工作階段時,將環境 ID 作為字串傳遞。

    配置選項

    套件

    packages 欄位在代理程式啟動前將套件預先安裝到容器中。套件由各自的套件管理器安裝,並在共享同一環境的工作階段中快取。當指定多個套件管理器時,它們按字母順序執行(apt、cargo、gem、go、npm、pip)。您可以選擇性地固定特定版本;預設為最新版本。

    支援的套件管理器:

    欄位套件管理器範例
    apt系統套件 (apt-get)"ffmpeg"
    cargoRust (cargo)"[email protected]"
    gemRuby (gem)"rails:7.1.0"
    goGo 模組"golang.org/x/tools/cmd/goimports@latest"
    npmNode.js (npm)"[email protected]"

    網路

    networking 欄位控制容器的出站網路存取。它不會影響 web_search 或 web_fetch 工具的允許網域。

    模式說明
    unrestricted完整的出站網路存取,除了一般安全封鎖清單。這是預設值。
    limited將容器網路存取限制為 allowed_hosts 清單。進一步的存取可透過 allow_package_managers 和 allow_mcp_servers 布林值啟用。

    對於生產部署,使用 limited 網路搭配明確的 allowed_hosts 清單。遵循最小權限原則,僅授予您的代理程式所需的最小網路存取權限,並定期審計您允許的網域。

    使用 limited 網路時:

    • allowed_hosts 指定容器可以到達的網域。這些必須以 HTTPS 為前綴。
    • allow_mcp_servers 允許出站存取在代理程式上配置的 MCP 伺服器端點,超出 allowed_hosts 陣列中列出的端點。預設為 false。
    • allow_package_managers 允許出站存取公開套件登錄(PyPI、npm 等),超出 allowed_hosts 陣列中列出的端點。預設為 false。

    環境生命週期

    • 環境會持續存在,直到明確存檔或刪除。
    • 多個工作階段可以參考同一個環境。
    • 每個工作階段都會獲得自己的容器實例。工作階段不共享檔案系統狀態。
    • 環境不進行版本控制。如果您經常更新環境,您可能想在您這一側記錄這些更新,以將環境狀態與工作階段對應。

    管理環境

    預先安裝的執行時環境

    雲端容器開箱即用包含常見的執行時環境。請參閱容器參考以取得預先安裝的語言、資料庫和公用程式的完整清單。

    Was this page helpful?

    session=$(curl -fsS https://api.anthropic.com/v1/sessions \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -H "anthropic-beta: managed-agents-2026-04-01" \
      -H "content-type: application/json" \
      --data @- <<EOF
    {
      "agent": "$agent_id",
      "environment_id": "$environment_id"
    }
    EOF
    )
    environment=$(curl -fsS https://api.anthropic.com/v1/environments \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -H "anthropic-beta: managed-agents-2026-04-01" \
      -H "content-type: application/json" \
      --data @- <<'EOF'
    {
      "name": "data-analysis",
      "config": {
        "type": "cloud",
        "packages": {
          "pip": ["pandas", "numpy", "scikit-learn"],
          "npm": ["express"]
        },
        "networking": {"type": "unrestricted"}
      }
    }
    EOF
    )
    pipPython (pip)"pandas==2.2.0"
    config=$(cat <<'EOF'
    {
      "type": "cloud",
      "networking": {
        "type": "limited",
        "allowed_hosts": ["api.example.com"],
        "allow_mcp_servers": true,
        "allow_package_managers": true
      }
    }
    EOF
    )
    # List environments
    environments=$(curl -fsS https://api.anthropic.com/v1/environments \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -H "anthropic-beta: managed-agents-2026-04-01")
    
    # Retrieve a specific environment
    env=$(curl -fsS "https://api.anthropic.com/v1/environments/$environment_id" \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -H "anthropic-beta: managed-agents-2026-04-01")
    
    # Archive an environment (read-only, existing sessions continue)
    curl -fsS -X POST "https://api.anthropic.com/v1/environments/$environment_id/archive" \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -H "anthropic-beta: managed-agents-2026-04-01"
    
    # Delete an environment (only if no sessions reference it)
    curl -fsS -X DELETE "https://api.anthropic.com/v1/environments/$environment_id" \
      -H "x-api-key: $ANTHROPIC_API_KEY" \
      -H "anthropic-version: 2023-06-01" \
      -H "anthropic-beta: managed-agents-2026-04-01"