---
title: 選擇代理環境
url: https://platform.claude.com/docs/zh-TW/managed-agents/choosing-an-environment
description: 決定 Claude Managed Agents 的工具和程式碼要在 Anthropic 管理的雲端環境中執行，還是在自行託管的沙箱中執行，並了解切換時會有哪些變化。
featureMetadata:
  topic:
    title: Managed Agents
    url: https://platform.claude.com/docs/en/managed-agents/overview
  status: beta
  betaHeader: managed-agents-2026-04-01
---

環境決定了您的代理的工具和程式碼在何處執行。它們在沙箱中執行。「Sandbox」（沙箱）是一個隔離的工作空間，例如容器，代理會在其中執行命令並處理檔案。您有兩個選項：

* **雲端環境：** Anthropic 為您執行沙箱。每個工作階段都會在 Anthropic 管理的基礎架構上取得自己全新的 Linux 容器，其中已預先安裝常用的程式語言、資料庫和公用程式。您可以選擇其網路規則以及要安裝的任何額外套件。
* **自行託管的沙箱：** 您在自己的基礎架構上執行沙箱。Claude 仍在 Anthropic 端執行，並決定接下來要呼叫哪個工具。一個由您執行、稱為「worker」（工作程式）的程式，會在您的機器上執行代理的 bash 和檔案工具呼叫，並將每個結果傳回。它也可以提供自訂工具。

無論您選擇哪一種，代理定義都相同。您是在[代理](https://platform.claude.com/docs/zh-TW/managed-agents/agent-setup)上設定模型、提示和工具，而不是在環境上設定。

## 從雲端環境開始

如果您不確定該選擇哪一種，或者您是 Claude Managed Agents 的新手，請像[快速入門](https://platform.claude.com/docs/zh-TW/managed-agents/quickstart)一樣，從[雲端環境](https://platform.claude.com/docs/zh-TW/managed-agents/environments)開始。Anthropic 會為每個工作階段執行一個隔離的容器，其中已預先安裝常用的程式語言和工具，因此您無需託管任何東西。只有在工具必須於您控制的基礎架構上執行時，才選擇自行託管的沙箱。

## 比較選項

下表比較這兩個選項。

|                    | [雲端環境](https://platform.claude.com/docs/zh-TW/managed-agents/environments)（預設）                                                                                                                                | [自行託管的沙箱](https://platform.claude.com/docs/zh-TW/managed-agents/self-hosted-sandboxes) |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| 工具和程式碼的執行位置        | Anthropic 管理的沙箱                                                                                                                                                                                               | 您的 worker，位於您的基礎架構上                                                                    |
| 哪些內容會傳送到 Anthropic | [對話歷史記錄](https://platform.claude.com/docs/zh-TW/managed-agents/events-and-streaming#list-past-events)、[工具結果](https://platform.claude.com/docs/zh-TW/managed-agents/tools#available-tools)、沙箱的檔案和狀態、技能以及記憶體儲存區 | 對話歷史記錄、工具結果、技能以及記憶體儲存區。沙箱的檔案和程序會保留在您的 worker 上。                                        |
| 您需要營運的項目           | 無                                                                                                                                                                                                             | worker 主機、其強化措施、其網路限制，以及您的 worker 用於驗證的環境金鑰                                            |
| 網路存取範圍             | 您在環境上設定的網路規則                                                                                                                                                                                                  | 您自己的網路政策                                                                               |
| 檔案和 GitHub 儲存庫掛載   | 由 Anthropic 管理                                                                                                                                                                                                | 由您管理                                                                                   |
| 記憶體儲存區             | 由 Anthropic 掛載於 `/mnt/memory/`                                                                                                                                                                                | 下載至 `/mnt/memory/` 並由 worker 同步                                                        |
| 沙箱生命週期             | 由 Anthropic 管理                                                                                                                                                                                                | 由您管理                                                                                   |
| 適用時機               | 預設選項。您不需要讓工具在自己的基礎架構上執行。                                                                                                                                                                                      | 工具必須在您控制的基礎架構上執行。                                                                      |

## 何時選擇自行託管的沙箱

當代理需要執行下列其中一項時，適合使用自行託管的沙箱：

* **處理無法離開您網路的資料：** 代理的檔案和程序會保留在您的 worker 上。工具傳回給模型的內容仍會傳送到 Managed Agents 服務。
* **存取無法公開路由的內部服務：** 代理的 bash 和檔案工具，以及您的 worker 提供的任何自訂工具，都在您的網路內執行。連線到代理的 MCP 伺服器的是 Anthropic，而不是您的 worker。私有的 MCP 伺服器可能位於您的內部工單系統或公司 wiki 前端。若要存取它，無論使用哪個選項，您都可以使用 [MCP 通道](https://platform.claude.com/docs/zh-TW/agents-and-tools/mcp-tunnels/overview)。MCP 通道目前處於研究預覽階段，需要申請存取權限。請參閱[自行託管沙箱與 MCP 通道](https://platform.claude.com/docs/zh-TW/managed-agents/self-hosted-sandboxes#self-hosted-sandboxes-and-mcp-tunnels)。
* **在您組織自己的合規與稽核控制下執行：** 工具在您設定、記錄和稽核的主機上執行。

## 自行託管的沙箱不會改變的事項

無論使用哪個選項，對話歷史記錄和工具結果都會傳送到由 Anthropic 營運的 Managed Agents 服務。這就是模型接收每次工具呼叫結果的方式。網頁搜尋和網頁擷取工具也在 Anthropic 端執行，而不是在沙箱中執行。請參閱[限制網頁搜尋與網頁擷取的網域](https://platform.claude.com/docs/zh-TW/managed-agents/tools-web-restrictions)。兩個選項都不會改變 Managed Agents 的合規涵蓋範圍，也不會改變其保留對話歷史記錄的時間長度。請參閱 [API 與資料保留](https://platform.claude.com/docs/zh-TW/manage-claude/api-and-data-retention#feature-eligibility)。

## 使用自行託管的沙箱時您需承擔與放棄的事項

自行託管的沙箱會讓您成為 worker 主機的營運者。您需要強化沙箱映像、控制網路輸出流量、儲存並輪替環境金鑰，以及將各工作階段彼此隔離。[安全模型](https://platform.claude.com/docs/zh-TW/managed-agents/self-hosted-sandboxes-security)頁面提供了詳細資訊。

您也會放棄下列雲端環境功能：

* [`file` 和 `github_repository` 工作階段資源](https://platform.claude.com/docs/zh-TW/managed-agents/self-hosted-sandboxes#session-resources)。您需要[自行準備輸入檔案](https://platform.claude.com/docs/zh-TW/managed-agents/self-hosted-sandboxes-workers#stage-files-for-a-session)，並且也需要負責掛載您自己的 GitHub 儲存庫。
* [儲存庫技能探索](https://platform.claude.com/docs/zh-TW/managed-agents/skills#load-skills-from-a-github-repository)。
* 保管庫中的[環境變數憑證](https://platform.claude.com/docs/zh-TW/managed-agents/vaults#add-a-credential)。
* 雲端沙箱的[預先安裝執行環境和套件](https://platform.claude.com/docs/zh-TW/managed-agents/cloud-sandboxes-reference)。自行託管的沙箱只會有您的 worker 所提供的內容。

## Claude Platform on AWS 上的差異

如果您透過 Claude Platform on AWS 使用 Claude Managed Agents，服務仍由 Anthropic 營運。在該平台上，自行託管的沙箱無法使用記憶體儲存區，worker 不使用環境金鑰，且無法使用 MCP 通道。請參閱 [Claude Platform on AWS 上的 Claude Managed Agents](https://platform.claude.com/docs/zh-TW/build-with-claude/claude-platform-on-aws#claude-managed-agents) 和[不支援的功能](https://platform.claude.com/docs/zh-TW/build-with-claude/claude-platform-on-aws#features-not-supported)。

## 從雲端環境切換到自行託管的沙箱

若要切換到自行託管的沙箱，您可以保留代理，建立一個 `self_hosted` 環境，並在新的工作階段和部署中參照其 ID。

* **會沿用的項目：** 代理定義、您的應用程式使用的 API 金鑰或 AWS 憑證、您的技能、您的 MCP 伺服器，以及您的[記憶體儲存區](https://platform.claude.com/docs/zh-TW/managed-agents/self-hosted-sandboxes-memory)。
* **新增的項目：** 一個 `self_hosted` 環境、一個您在 Claude Console 中產生的環境金鑰，以及一個由您執行的 worker。[自行託管的沙箱快速入門](https://platform.claude.com/docs/zh-TW/managed-agents/self-hosted-sandboxes#quickstart)涵蓋了這三項。
* **將停止運作的項目：** [使用自行託管的沙箱時您需承擔與放棄的事項](https://platform.claude.com/docs/zh-TW/managed-agents/choosing-an-environment#what-you-take-on-and-give-up-with-a-self-hosted-sandbox)中列出的功能。

在 Claude Platform on AWS 上，記憶體儲存區不會沿用到自行託管的沙箱，且 worker 不使用環境金鑰。請參閱 [Claude Platform on AWS 上的差異](https://platform.claude.com/docs/zh-TW/managed-agents/choosing-an-environment#differences-on-claude-platform-on-aws)。
