---
title: 保護您的 Managed Agents 部署
url: https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment
description: 限制您的代理可以存取和執行哪些內容的設定，依重要性由高至低排列。
featureMetadata:
  topic:
    title: Managed Agents
    url: https://platform.claude.com/docs/en/managed-agents/overview
  status: beta
  betaHeader: managed-agents-2026-04-01
---

本指南列出限制 Claude Managed Agents 上的代理可以存取和執行哪些內容的設定，依重要性由高至低排列。每個章節都會連結到完整說明該設定的頁面。

| 章節                                                                                                                                                                | 設定或決策                                          | 建議                                                                                                                                 |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| [選擇代理的執行位置](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment#choose-where-the-agent-runs)                                                  | 雲端或自行託管的沙箱                                     | 雲端，除非工具必須在您控制的基礎架構上執行                                                                                                              |
| [限制網路](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment#limit-the-network)                                                                 | 環境的 `networking.type`                          | `limited`，且僅包含代理需要的主機                                                                                                              |
| [將憑證保存在保管庫中](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment#keep-credentials-in-vaults)                                                  | 每個環境變數憑證上的 `injection_location` 和 `networking` | 僅限請求標頭，並使用 `limited` 網路，且僅包含該金鑰所對應的主機                                                                                              |
| [限制網頁搜尋和網頁擷取](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment#restrict-web-search-and-web-fetch)                                          | 每個網頁工具上的 `allowed_domains`                     | 在每個工具上設定允許清單。在 `web_fetch` 上，僅列出代理需要的網站。在 `web_search` 上，列出您希望取得結果的網站                                                              |
| [核准有風險的動作](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment#approve-risky-actions)                                                         | 每個工具上的 `permission_policy`                     | 在 `bash`、`write`、`edit`、`web_fetch` 以及僅讀取資料的 MCP 工具上使用 `auto`。如果您無法在沙箱外復原某個工具所做的變更，或者不應僅因轉送的終端使用者文字就讓該工具執行，則改為在該工具上使用 `always_ask` |
| [為代理提供最小的工具集](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment#give-the-agent-the-smallest-tool-set)                                       | 代理工具集上的 `default_config.enabled`               | `false`，然後啟用代理需要的工具                                                                                                                |
| [讓不受信任的輸入遠離強大的工具](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment#keep-untrusted-input-away-from-powerful-tools)                          | 代理在讀取不受信任的輸入時持有哪些工具和憑證                         | 任何讀取不受信任輸入的代理，都不應持有設為 `always_allow` 且會寫入檔案、執行命令或變更記錄的工具                                                                           |
| [設定限制和停止方式](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment#set-limits-and-a-way-to-stop)                                                 | 每個工作階段和部署上的 `budget`                           | 依您預期單次執行的成本來設定上限                                                                                                                   |
| [可選擇讓離線審查者閱讀每份對話紀錄](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment-monitoring#optionally-have-an-offline-reviewer-read-every-transcript) | 由您執行、讀取每個工作階段事件的離線審查作業                         | 選擇性。依排程審查每個進入閒置或已終止的工作階段                                                                                                           |
| [監控工作階段並檢視保留政策](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment-monitoring#monitor-sessions-and-review-retention)                         | Webhook 和工作階段刪除                                | 在工作階段進入閒置、達到預算或終止時發出警示，並檢查其進入閒置的原因。將您想保留的事件儲存在您自己的日誌中，並刪除不再需要的工作階段                                                                 |

[安全風險與沙箱邊界](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment-risks)說明了這些設定為何重要，以及它們無法防範哪些情況。若要審查和監控工作階段，請參閱[審查與監控代理工作階段](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment-monitoring)。

## 選擇代理的執行位置

代理的工具在何處執行，決定了由誰負責保護沙箱：使用雲端環境時由 Anthropic 負責，使用自行託管的沙箱時則由您負責。若要在兩者之間做選擇，並了解每種方式會有哪些內容傳送到 Anthropic，請參閱[選擇代理環境](https://platform.claude.com/docs/zh-TW/managed-agents/choosing-an-environment)。

如果您使用[自行託管的沙箱](https://platform.claude.com/docs/zh-TW/managed-agents/self-hosted-sandboxes)，請記住以下四點：

* **網路：** [限制網路](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment#limit-the-network)適用於雲端環境。對於自行託管的沙箱，請在您自己的防火牆中對其流量設定同等的限制。您的防火牆不會限制代理所宣告的 MCP 伺服器，因此請審查這些伺服器，以及您的應用程式為工作階段設定的任何伺服器。
* **網頁工具：** 網頁工具在 Anthropic 的伺服器上執行，因此您的防火牆不會限制它們。請使用它們的網域清單來加以限制。請參閱[限制網頁搜尋和網頁擷取](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment#restrict-web-search-and-web-fetch)。
* **憑證：** 自行託管的沙箱尚不支援環境變數憑證。
* **隔離與強化：** 兩者皆由您負責。請參閱[安全模型](https://platform.claude.com/docs/zh-TW/managed-agents/self-hosted-sandboxes-security)。

兩種選項都不會改變 Managed Agents 的合規涵蓋範圍，也不會改變其保留工作階段歷史記錄的時間長度。請參閱[監控工作階段並檢視保留政策](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment-monitoring#monitor-sessions-and-review-retention)。

## 限制網路

將 `networking.type` 設為 `limited`，並在 `allowed_hosts` 中僅列出代理需要的主機。省略 `networking` 的環境建立請求可能會得到 `unrestricted`，因此請在每個建立請求中都設定 `networking`。請參閱[不受限網路的風險](https://platform.claude.com/docs/zh-TW/managed-agents/environments#risks-of-unrestricted-networking)。

無論 `allowed_hosts` 如何設定，您附加的檔案、記憶體儲存區和 GitHub 儲存庫都會持續提供給代理使用。

本頁的範例使用一個客服代理。它會讀取客戶的工單、查詢訂單、閱讀您的說明中心，並草擬回覆。訂單查詢由您的應用程式執行，不需要任何主機，因此此環境只允許一個主機，也就是供 `web_fetch` 使用的說明中心：

<CodeGroup defaultLanguage="CLI">
  ```bash cURL
  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" \
    -d '{
      "name": "support-agent",
      "config": {
        "type": "cloud",
        "networking": {
          "type": "limited",
          "allowed_hosts": ["help.example.com"]
        }
      }
    }'
  ```

  <CodeGroupItem>
    ```bash CLI
    ant apply environment.yaml
    ```

    <File filename="environment.yaml">
      ```yaml
      # yaml-language-server: $schema=https://platform.claude.com/schemas/ant/beta/environment.json
      name: support-agent
      config:
        type: cloud
        networking:
          type: limited
          allowed_hosts:
            - help.example.com
      ```
    </File>
  </CodeGroupItem>

  ```python Python
  environment = client.beta.environments.create(
      name="support-agent",
      config={
          "type": "cloud",
          "networking": {
              "type": "limited",
              "allowed_hosts": ["help.example.com"],
          },
      },
  )
  ```

  ```typescript TypeScript
  const environment = await client.beta.environments.create({
    name: "support-agent",
    config: {
      type: "cloud",
      networking: {
        type: "limited",
        allowed_hosts: ["help.example.com"]
      }
    }
  });
  ```

  ```csharp C#
  using Anthropic.Models.Beta.Environments;

  var environment = await client.Beta.Environments.Create(new()
  {
      Name = "support-agent",
      Config = new BetaCloudConfigParams
      {
          Networking = new BetaLimitedNetworkParams
          {
              AllowedHosts = ["help.example.com"],
          },
      },
  });
  ```

  ```go Go
  environment, err := client.Beta.Environments.New(ctx, anthropic.BetaEnvironmentNewParams{
  	Name: "support-agent",
  	Config: anthropic.BetaEnvironmentNewParamsConfigUnion{
  		OfCloud: &anthropic.BetaCloudConfigParams{
  			Networking: anthropic.BetaCloudConfigParamsNetworkingUnion{
  				OfLimited: &anthropic.BetaLimitedNetworkParams{
  					AllowedHosts: []string{"help.example.com"},
  				},
  			},
  		},
  	},
  })
  if err != nil {
  	panic(err)
  }
  _ = environment
  ```

  ```java Java
  import com.anthropic.models.beta.environments.*;
  import java.util.List;

  var environment = client.beta().environments().create(EnvironmentCreateParams.builder()
      .name("support-agent")
      .config(BetaCloudConfigParams.builder()
          .networking(BetaLimitedNetworkParams.builder()
              .allowedHosts(List.of("help.example.com"))
              .build())
          .build())
      .build());
  ```

  ```php PHP
  $environment = $client->beta->environments->create(
      name: 'support-agent',
      config: [
          'type' => 'cloud',
          'networking' => [
              'type' => 'limited',
              'allowed_hosts' => ['help.example.com'],
          ],
      ],
  );
  ```

  ```ruby Ruby
  environment = client.beta.environments.create(
    name: "support-agent",
    config: {
      type: "cloud",
      networking: {
        type: "limited",
        allowed_hosts: ["help.example.com"]
      }
    }
  )
  ```
</CodeGroup>

`limited` 環境有三項網路設定：

| 設定                       | 對沙箱中的程式碼開放的內容                                                                                                                                                                                        | 建議                                                                                                 |
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| `allowed_hosts`          | 您列出的主機，適用於任何請求                                                                                                                                                                                       | 僅限代理需要的主機，包括您營運或信任的每個 MCP 伺服器的主機                                                                   |
| `allow_package_managers` | [套件管理器主機](https://platform.claude.com/docs/zh-TW/managed-agents/environments#package-manager-hosts)。其中包括 `github.com`、`gitlab.com` 和 `bitbucket.org` 上的每個儲存庫和路徑，任何人都可以在這些地方發布內容，而沙箱中的程式碼也可以上傳檔案到這些地方 | `false`，除非環境的 `packages` 設定列出了套件，此時必須設為 `true`。如果代理在執行期間會安裝套件，請改為在 `allowed_hosts` 中僅列出它需要的套件登錄庫主機 |
| `allow_mcp_servers`      | 不開放任何主機。Managed Agents 從 Anthropic 的伺服器連線到 MCP 伺服器                                                                                                                                                   | `false`，並在 `allowed_hosts` 中列出您營運或信任的每個 MCP 伺服器的主機                                                 |

`allow_package_managers` 和 `allow_mcp_servers` 設定不會為網頁搜尋和網頁擷取新增任何主機。

請將 `allow_mcp_servers` 保持關閉（這是預設值），並在 `allowed_hosts` 中列出您營運或信任的每個 MCP 伺服器的主機。您列出的每個主機也會對沙箱中的程式碼開放。在 `allow_mcp_servers` 關閉的情況下，如果 MCP 伺服器的主機未被列出，工作階段建立時的檢查會拒絕該請求。請參閱[在建立工作階段時提供驗證](https://platform.claude.com/docs/zh-TW/managed-agents/mcp-connector#provide-authentication-at-session-creation)。當工作階段更新變更 `mcp_servers` 時，也會執行相同的檢查。

<Warning>
  網路存取是依主機授予，而非依操作授予。沙箱可以向允許的主機傳送任何請求，包括 `git push` 和套件發布等上傳操作。它也可以使用命令所提供的任何憑證，即使是有人藏在代理所讀取文字中的憑證。
</Warning>

為 `allowed_hosts` 選擇主機時，請遵循以下兩條規則：

* 僅列出您營運或信任的主機。
* 避免使用 `*.` 萬用字元，以及任何人都可以發布內容的共用託管網域。

如果代理保留 `bash`，請依照[核准有風險的動作](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment#approve-risky-actions)的說明設定 `bash` 工具的[權限政策](https://platform.claude.com/docs/zh-TW/managed-agents/permission-policies)。

<Note>
  收緊環境設定後，請啟動新的工作階段，並停止已在執行中的工作階段。已在執行中的工作階段可能會沿用舊的限制，直到結束為止。請參閱[設定限制和停止方式](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment#set-limits-and-a-way-to-stop)。
</Note>

如需所有網路設定，請參閱[雲端環境設定](https://platform.claude.com/docs/zh-TW/managed-agents/environments#networking)。

## 將憑證保存在保管庫中

將每個機密儲存在保管庫中。對於每個環境變數憑證，請將注入位置設為僅限請求標頭，並僅列出該機密所對應的主機。沙箱中的程式碼看到的是佔位符，而非機密本身。Managed Agents 只會在傳送至憑證所允許主機的對外 HTTPS 請求中將佔位符替換為真正的機密。因此，除非某個服務將機密傳回（例如會回顯請求標頭的端點），否則模型無法直接接觸到該機密。如果憑證的 `networking` 為 `unrestricted`，Managed Agents 會在傳送至環境允許沙箱存取的任何主機的請求中將佔位符替換為真正的機密。若要使用保管庫，請在建立工作階段或部署時，於 `vault_ids` 中傳入其 ID。

| 設定                   | 設定值                                                                                            | 原因                                                                               | 它不會做的事                                          |
| -------------------- | ---------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ----------------------------------------------- |
| `injection_location` | `{"header": true, "body": false}`，在您確認服務會從標頭讀取金鑰之後                                             | 請求主體通常是由代理讀取的內容建構而成，因此放在主體中的金鑰暴露風險較高。請明確指定兩個欄位：省略此物件的建立請求會同時啟用兩個位置，而更新只會變更您傳送的欄位 | 程式碼仍可在憑證允許的每個主機上使用該金鑰。預期在主體中收到金鑰的服務會收到佔位符並拒絕該請求 |
| 憑證上的 `networking`    | `limited`，並列出該金鑰所對應的確切主機                                                                       | 回應會以未遮蔽的形式傳回沙箱，因此請避免使用萬用字元、共用託管網域，以及會回顯請求標頭的主機                                   | 它不會開放該主機。環境也必須允許該主機                             |
| 金鑰的權限，在核發金鑰的服務端設定    | 僅限代理需要的權限                                                                                      | 代理可以執行金鑰允許的任何操作                                                                  | 不適用                                             |
| 已掛載儲存庫的 GitHub 權杖    | 具有最低權限的[細粒度權杖](https://platform.claude.com/docs/zh-TW/managed-agents/github#token-permissions) | 沙箱中的程式碼可以在整個工作階段期間使用它從已掛載的儲存庫擷取和推送。僅在代理必須推送時才授予寫入權限                              | 不適用                                             |

客服代理不需要保管庫憑證，因為您的應用程式持有您訂單 API 的 API 金鑰。如果您的代理確實持有保管庫憑證，請參閱[新增憑證](https://platform.claude.com/docs/zh-TW/managed-agents/vaults#add-a-credential)以取得各種語言的請求範例。

請勿將金鑰放在系統提示、代理定義和訊息中。不要給代理 Claude API 金鑰。即使 Claude API 金鑰存放在保管庫中，沙箱中的程式碼仍可使用它直接呼叫 Claude API。它可以執行該金鑰允許的任何操作，例如啟動或刪除工作階段，或使用網頁搜尋和網頁擷取。代理的工具設定、核准和預算都不適用於這些呼叫。在 `limited` 環境中，只有當 `allowed_hosts` 允許沙箱存取 `api.anthropic.com` 時，程式碼才能進行這些呼叫。

請自行擷取權杖並將其儲存在保管庫中，因為沙箱中的程式碼使用已儲存機密所擷取的權杖會以未遮蔽的形式傳回。

請將不同信任等級工作負載的保管庫放在不同的[工作區](https://platform.claude.com/docs/zh-TW/manage-claude/workspaces)中，因為任何可存取某個工作區的 API 金鑰都可以參照該工作區的保管庫。請使用範圍限定於單一工作區的 API 金鑰。

如需 MCP 憑證和輪替的相關資訊，請參閱[使用 vault 進行驗證](https://platform.claude.com/docs/zh-TW/managed-agents/vaults)。

## 限制網頁搜尋和網頁擷取

將 `web_fetch` 上的 `allowed_domains` 設為代理需要的網站。代理擷取的任何 URL 都可能將資料帶到其所指向的網站，因此這份清單是一項安全控制措施。在 `web_search` 上，將 `allowed_domains` 設為您希望取得結果的網站，讓結果只來自您信任其準確性的網站。這份清單無法阻止搜尋查詢傳送到搜尋服務提供者。搜尋結果包含網頁中的文字，因此這份清單也會限制哪些網站的文字能傳到代理。請在每種類型的環境中，為兩個工具都設定 `allowed_domains`。

`blocked_domains` 清單會封鎖您列出的主機及其子網域，但不會封鎖其他任何主機。相同的內容仍可能透過網頁封存、快取、鏡像或您未列出的相關網域傳到代理。請勿依賴 `blocked_domains` 來確保安全。請使用 `allowed_domains` 並指定您信任的主機。

在 `limited` 環境中，[限制網路](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment#limit-the-network)中的 `allowed_hosts` 清單也會限制網頁工具。`unrestricted` 環境或自行託管的沙箱不會限制網頁工具。

| 在 `limited` 環境中                                        | 結果                                                                                                      |
| ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- |
| 已啟用網頁工具上的某個 `allowed_domains` 項目不在 `allowed_hosts` 範圍內 | 建立工作階段會失敗並傳回 400 錯誤，新增此類項目的工作階段更新也會失敗。由部署啟動的工作階段（無論是依排程或手動執行）仍會被建立。之後該工具不會從 `allowed_hosts` 以外的主機傳回任何內容 |
| 網頁工具沒有自己的清單                                            | 該工具只會傳回來自 `allowed_hosts` 中主機的網頁和結果。請同時在該工具上設定 `allowed_domains`                                        |
| `allowed_hosts` 沒有任何項目                                 | 兩個網頁工具都不會傳回任何網頁或搜尋結果                                                                                    |
| 您為網頁工具將某個主機新增到 `allowed_hosts`                         | 該主機也會對沙箱中的程式碼開放                                                                                         |

兩份清單比對主機的方式不同：

| 清單                      | 項目              | 符合                   | 不符合               |
| ----------------------- | --------------- | -------------------- | ----------------- |
| `allowed_hosts`（環境）     | `example.com`   | `example.com`        | `www.example.com` |
| `allowed_hosts`（環境）     | `*.example.com` | 每個子網域                | `example.com`     |
| `allowed_domains`（網頁工具） | `example.com`   | `example.com` 及每個子網域 | 其他網域              |

如果代理需要某個網站及其所有子網域，請在 `allowed_hosts` 中同時列出 `example.com` 和 `*.example.com`，否則請列出確切的主機。如果某個工具列出 `example.com`，而 `allowed_hosts` 只列出 `*.example.com`，工作階段仍會被建立。工作階段建立時的檢查會將 `example.com` 視為在 `*.example.com` 範圍內，但該工具不會從 `example.com` 本身傳回任何內容。如需兩份清單的比對方式，請參閱[在代理上設定網域清單](https://platform.claude.com/docs/zh-TW/managed-agents/tools-web-restrictions#set-domain-lists-on-an-agent)。

`web_fetch` 工具也只會開啟已在工作階段中出現過的 URL：

| URL 出現的位置                                | `web_fetch` 是否可以開啟          |
| ---------------------------------------- | --------------------------- |
| 使用者訊息的文字，包括您轉送的終端使用者文字                   | 是                           |
| `user.define_outcome` 事件的描述              | 是                           |
| 網頁搜尋結果的位址                                | 是                           |
| `web_fetch` 先前傳回的網頁文字（非 PDF），其中顯示了完整 URL | 是                           |
| 自訂工具結果的文字，當 Claude 直接呼叫該工具時              | 是，除非結果被標記為 `is_error: true` |
| 系統提示                                     | 否                           |
| 代理的設定，包括 `allowed_domains` 項目            | 否                           |
| Claude 自己的輸出                             | 否                           |
| `bash` 和其他沙箱工具的輸出                        | 否                           |
| MCP 工具結果                                 | 否                           |
| 附加到使用者訊息的檔案                              | 否                           |

在多代理工作階段中，只有當來自另一個代理的 URL 是透過標記為「是」的來源傳到該代理時，`web_fetch` 才會開啟它。直接呼叫所得的自訂工具結果算作標記為「是」的來源。即使其文字是由 Claude 撰寫的也是如此，例如當工具重複其輸入時。即使 URL 在撰寫時沒有 `https://`（例如 `example.com/docs`），也可能被計入。`web_fetch` 工具不一定能開啟以文字而非 URL 顯示的連結，例如「Contact support」。如果代理必須擷取尚未在工作階段中出現過的 URL，請在使用者訊息中傳送該 URL。

此規則可降低注入的文字建構出夾帶私人資料之 URL 的機會。終端使用者文字、搜尋結果、擷取的網頁和自訂工具結果仍可能新增 URL，因此請保持設定 `allowed_domains`。Messages API 套用類似的規則，但來源清單不同。請參閱 [URL 驗證](https://platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/web-fetch-tool#url-validation)。

`web_fetch` 上的網域清單不會限制 `bash` 工具。請同時[限制網路](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment#limit-the-network)。請參閱[網域清單規則](https://platform.claude.com/docs/zh-TW/managed-agents/tools-web-restrictions#domain-list-rules)。

## 核准有風險的動作

在 `bash`、`write`、`edit` 和 `web_fetch`，以及僅讀取資料的 MCP 工具上設定 `auto`。如果您無法在沙箱外復原某個工具所做的變更，請改為在該工具上使用 `always_ask`。對於不應僅因您轉送的終端使用者文字要求就執行的工具，也請使用它。[權限政策](https://platform.claude.com/docs/zh-TW/managed-agents/permission-policies)決定工具呼叫是直接執行、等待您的核准，還是由伺服器評估。

| 工具                    | 建議的政策                                                                                      | 原因                                            |
| --------------------- | ------------------------------------------------------------------------------------------ | --------------------------------------------- |
| `read`、`glob`、`grep`  | `always_allow`                                                                             | 它們讀取沙箱中的檔案，不會變更任何內容                           |
| `bash`、`write`、`edit` | `auto`。如果您無法在沙箱外復原某個工具所做的變更，請在該工具上使用 `always_ask`。如果您會轉送終端使用者文字，請在 `bash` 上使用 `always_ask` | 代理工具集的預設值為 `always_allow`，會在未經核准的情況下執行每個呼叫    |
| `web_fetch`           | `auto`                                                                                     | 代理擷取的 URL 可能將資料帶到其所指向的網站                      |
| `web_search`          | 如果代理處理的資料是您不希望在搜尋查詢中傳送的，請使用 `always_ask`。否則使用 `always_allow`                               | `allowed_domains` 限制的是結果來自哪些網站，而非查詢包含的內容      |
| 僅讀取資料的 MCP 工具         | `auto`，在工具集的 `configs` 中為每個工具個別設定                                                          | 工具集預設值維持 `always_ask`，因此 MCP 伺服器之後新增的工具仍會等待核准 |
| 會變更資料的 MCP 工具         | `always_ask`                                                                               | 這是 MCP 工具集的預設值。請保留它                           |
| 自訂工具                  | 由您的程式碼決定每個呼叫是否執行                                                                           | 權限政策不適用                                       |

[為代理提供最小的工具集](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment#give-the-agent-the-smallest-tool-set)中的工具集套用了這些政策。

[`auto` 政策](https://platform.claude.com/docs/zh-TW/managed-agents/permission-policies#let-the-server-evaluate-each-call-with-auto)讓伺服器執行呼叫、拒絕呼叫或暫停以等待核准。在長時間的執行中，人員無法核准每個呼叫，因此改由伺服器檢查每個呼叫。請將 `auto` 與受限網路、權限範圍狹窄的金鑰、預算以及閒置工作階段警示搭配使用。`auto` 並非人工檢查點，因此如果必須由人員在工具呼叫執行前進行審查，請在該工具上設定 `always_ask`。

`auto` 會將 `user.message` 事件中的文字以及 `user.define_outcome` 事件中的描述視為您的指示，包括您轉送的終端使用者文字。

暫停的工作階段會無限期等待，因此無人看管的工作階段需要一個能回應暫停呼叫或中斷工作階段的用戶端。

在允許每個暫停的呼叫之前，請先審查它。一個未向人員顯示就允許每個呼叫的用戶端，等同於 `always_allow`。請參閱[回應確認請求](https://platform.claude.com/docs/zh-TW/managed-agents/permission-policies#respond-to-confirmation-requests)和[查看每次呼叫的評估方式](https://platform.claude.com/docs/zh-TW/managed-agents/permission-policies#see-how-each-call-was-evaluated)。

## 為代理提供最小的工具集

將 `default_config.enabled` 設為 `false`，並[僅啟用代理需要的工具](https://platform.claude.com/docs/zh-TW/managed-agents/tools#enabling-only-specific-tools)。代理工具集預設會啟用全部八個內建工具。

| 工具                       | 功能                             |
| ------------------------ | ------------------------------ |
| `bash`                   | 執行任何命令，包括對允許主機的請求              |
| `write`、`edit`           | 變更沙箱中的檔案                       |
| `read`、`glob`、`grep`     | 讀取沙箱中的檔案                       |
| `web_fetch`、`web_search` | 透過 Anthropic 的伺服器，從網路傳回網頁和搜尋結果 |

客服代理需要三個內建工具：用於草稿的 `read` 和 `write`，以及用於說明中心的 `web_fetch`。它透過由您的應用程式執行的[自訂工具](https://platform.claude.com/docs/zh-TW/managed-agents/tools#custom-tools) `lookup_order` 查詢訂單。您的應用程式持有您訂單 API 的 API 金鑰，因此代理既不需要 `bash`，也不需要憑證。

以下範例使用 `allowed_domains` 將 `web_fetch` 限制為 `help.example.com`。它依照[核准有風險的動作](https://platform.claude.com/docs/zh-TW/managed-agents/secure-deployment#approve-risky-actions)的建議，在 `write` 和 `web_fetch` 上設定 `auto`。如果客戶的工單導致代理使用這些工具，代理只能變更沙箱中的檔案或開啟說明中心的網頁。這就是兩個工具都不需要 `always_ask` 的原因。此範例也在 `default_config` 中設定了 `always_ask`，因此您之後啟用但未設定自身政策的工具會使用 `always_ask`：

<CodeGroup defaultLanguage="CLI">
  ```bash cURL
  tools='[
    {
      "type": "agent_toolset_20260401",
      "default_config": {
        "enabled": false,
        "permission_policy": {"type": "always_ask"}
      },
      "configs": [
        {"name": "read", "enabled": true, "permission_policy": {"type": "always_allow"}},
        {"name": "write", "enabled": true, "permission_policy": {"type": "auto"}},
        {
          "name": "web_fetch",
          "enabled": true,
          "allowed_domains": ["help.example.com"],
          "permission_policy": {"type": "auto"}
        }
      ]
    },
    {
      "type": "custom",
      "name": "lookup_order",
      "description": "Look up one order by its ID. Returns the status, the items, and the delivery date.",
      "input_schema": {
        "type": "object",
        "properties": {
          "order_id": {"type": "string", "description": "The order ID from the ticket"}
        },
        "required": ["order_id"]
      }
    }
  ]'
  ```

  <CodeGroupItem>
    ```bash CLI
    ant apply agent.md
    ```

    <File filename="agent.md">
      ```markdown
      ---
      name: Support Agent
      model: claude-opus-5-5
      tools:
        - type: agent_toolset_20260401
          default_config:
            enabled: false
            permission_policy:
              type: always_ask
          configs:
            - name: read
              enabled: true
              permission_policy:
                type: always_allow
            - name: write
              enabled: true
              permission_policy:
                type: auto
            - name: web_fetch
              enabled: true
              allowed_domains: [help.example.com]
              permission_policy:
                type: auto
        - type: custom
          name: lookup_order
          description: Look up one order by its ID. Returns the status, the items, and the delivery date.
          input_schema:
            type: object
            properties:
              order_id:
                type: string
                description: The order ID from the ticket
            required:
              - order_id
      ---
      ```
    </File>
  </CodeGroupItem>

  ```python Python
  tools = [
      {
          "type": "agent_toolset_20260401",
          "default_config": {
              "enabled": False,
              "permission_policy": {"type": "always_ask"},
          },
          "configs": [
              {
                  "name": "read",
                  "enabled": True,
                  "permission_policy": {"type": "always_allow"},
              },
              {
                  "name": "write",
                  "enabled": True,
                  "permission_policy": {"type": "auto"},
              },
              {
                  "name": "web_fetch",
                  "enabled": True,
                  "allowed_domains": ["help.example.com"],
                  "permission_policy": {"type": "auto"},
              },
          ],
      },
      {
          "type": "custom",
          "name": "lookup_order",
          "description": "Look up one order by its ID. Returns the status, the items, and the delivery date.",
          "input_schema": {
              "type": "object",
              "properties": {
                  "order_id": {
                      "type": "string",
                      "description": "The order ID from the ticket",
                  },
              },
              "required": ["order_id"],
          },
      },
  ]
  ```

  ```typescript TypeScript
  const tools = [
    {
      type: "agent_toolset_20260401",
      default_config: {
        enabled: false,
        permission_policy: { type: "always_ask" }
      },
      configs: [
        {
          name: "read",
          enabled: true,
          permission_policy: { type: "always_allow" }
        },
        {
          name: "write",
          enabled: true,
          permission_policy: { type: "auto" }
        },
        {
          name: "web_fetch",
          enabled: true,
          allowed_domains: ["help.example.com"],
          permission_policy: { type: "auto" }
        }
      ]
    },
    {
      type: "custom",
      name: "lookup_order",
      description:
        "Look up one order by its ID. Returns the status, the items, and the delivery date.",
      input_schema: {
        type: "object",
        properties: {
          order_id: { type: "string", description: "The order ID from the ticket" }
        },
        required: ["order_id"]
      }
    }
  ] satisfies Anthropic.Beta.AgentCreateParams["tools"];
  ```

  ```csharp C#
  using System.Text.Json;
  using Anthropic.Models.Beta.Agents;
  using Tool = Anthropic.Models.Beta.Agents.Tool;

  Tool[] tools =
  [
      new BetaManagedAgentsAgentToolset20260401Params
      {
          Type = BetaManagedAgentsAgentToolset20260401ParamsType.AgentToolset20260401,
          DefaultConfig = new()
          {
              Enabled = false,
              PermissionPolicy = new BetaManagedAgentsAlwaysAskPolicy { Type = "always_ask" },
          },
          Configs =
          [
              new BetaManagedAgentsReadToolConfigParams
              {
                  Enabled = true,
                  PermissionPolicy = new BetaManagedAgentsAlwaysAllowPolicy { Type = "always_allow" },
              },
              new BetaManagedAgentsWriteToolConfigParams
              {
                  Enabled = true,
                  PermissionPolicy = new BetaManagedAgentsAutoPolicy(),
              },
              new BetaManagedAgentsWebFetchToolConfigParams
              {
                  Enabled = true,
                  AllowedDomains = ["help.example.com"],
                  PermissionPolicy = new BetaManagedAgentsAutoPolicy(),
              },
          ],
      },
      new BetaManagedAgentsCustomToolParams
      {
          Type = "custom",
          Name = "lookup_order",
          Description = "Look up one order by its ID. Returns the status, the items, and the delivery date.",
          InputSchema = new()
          {
              Properties = new Dictionary<string, JsonElement>
              {
                  ["order_id"] = JsonSerializer.SerializeToElement(
                      new { type = "string", description = "The order ID from the ticket" }
                  ),
              },
              Required = ["order_id"],
          },
      },
  ];
  ```

  ```go Go
  tools := []anthropic.BetaAgentNewParamsToolUnion{{
  	OfAgentToolset20260401: &anthropic.BetaManagedAgentsAgentToolset20260401Params{
  		Type: anthropic.BetaManagedAgentsAgentToolset20260401ParamsTypeAgentToolset20260401,
  		DefaultConfig: anthropic.BetaManagedAgentsAgentToolsetDefaultConfigParams{
  			Enabled: anthropic.Bool(false),
  			PermissionPolicy: anthropic.BetaManagedAgentsAgentToolsetDefaultConfigParamsPermissionPolicyUnion{
  				OfAlwaysAsk: &anthropic.BetaManagedAgentsAlwaysAskPolicyParam{
  					Type: anthropic.BetaManagedAgentsAlwaysAskPolicyTypeAlwaysAsk,
  				},
  			},
  		},
  		Configs: []anthropic.BetaManagedAgentsAgentToolConfigParamsUnion{
  			{OfRead: &anthropic.BetaManagedAgentsReadToolConfigParams{
  				Enabled: anthropic.Bool(true),
  				PermissionPolicy: anthropic.BetaManagedAgentsReadToolConfigParamsPermissionPolicyUnion{
  					OfAlwaysAllow: &anthropic.BetaManagedAgentsAlwaysAllowPolicyParam{
  						Type: anthropic.BetaManagedAgentsAlwaysAllowPolicyTypeAlwaysAllow,
  					},
  				},
  			}},
  			{OfWrite: &anthropic.BetaManagedAgentsWriteToolConfigParams{
  				Enabled: anthropic.Bool(true),
  				PermissionPolicy: anthropic.BetaManagedAgentsWriteToolConfigParamsPermissionPolicyUnion{
  					OfAuto: &anthropic.BetaManagedAgentsAutoPolicyParam{},
  				},
  			}},
  			{OfWebFetch: &anthropic.BetaManagedAgentsWebFetchToolConfigParams{
  				AllowedDomains: []string{"help.example.com"},
  				Enabled:        anthropic.Bool(true),
  				PermissionPolicy: anthropic.BetaManagedAgentsWebFetchToolConfigParamsPermissionPolicyUnion{
  					OfAuto: &anthropic.BetaManagedAgentsAutoPolicyParam{},
  				},
  			}},
  		},
  	},
  }, {
  	OfCustom: &anthropic.BetaManagedAgentsCustomToolParams{
  		Type:        anthropic.BetaManagedAgentsCustomToolParamsTypeCustom,
  		Name:        "lookup_order",
  		Description: "Look up one order by its ID. Returns the status, the items, and the delivery date.",
  		InputSchema: anthropic.BetaManagedAgentsCustomToolInputSchemaParam{
  			Properties: map[string]any{
  				"order_id": map[string]any{
  					"type":        "string",
  					"description": "The order ID from the ticket",
  				},
  			},
  			Required: []string{"order_id"},
  		},
  	},
  }}
  _ = tools
  ```

  ```java Java
  import com.anthropic.core.JsonValue;
  import com.anthropic.models.beta.agents.*;
  import java.util.List;
  import java.util.Map;

  var tools = List.of(
      AgentCreateParams.Tool.ofAgentToolset20260401(
          BetaManagedAgentsAgentToolset20260401Params.builder()
              .type(BetaManagedAgentsAgentToolset20260401Params.Type.AGENT_TOOLSET_20260401)
              .defaultConfig(
                  BetaManagedAgentsAgentToolsetDefaultConfigParams.builder()
                      .enabled(false)
                      .permissionPolicy(
                          BetaManagedAgentsAlwaysAskPolicy.builder()
                              .type(BetaManagedAgentsAlwaysAskPolicy.Type.ALWAYS_ASK)
                              .build()
                      )
                      .build()
              )
              .addConfig(
                  BetaManagedAgentsReadToolConfigParams.builder()
                      .enabled(true)
                      .permissionPolicy(
                          BetaManagedAgentsAlwaysAllowPolicy.builder()
                              .type(BetaManagedAgentsAlwaysAllowPolicy.Type.ALWAYS_ALLOW)
                              .build()
                      )
                      .build()
              )
              .addConfig(
                  BetaManagedAgentsWriteToolConfigParams.builder()
                      .enabled(true)
                      .permissionPolicy(BetaManagedAgentsAutoPolicy.builder().build())
                      .build()
              )
              .addConfig(
                  BetaManagedAgentsWebFetchToolConfigParams.builder()
                      .enabled(true)
                      .allowedDomains(List.of("help.example.com"))
                      .permissionPolicy(BetaManagedAgentsAutoPolicy.builder().build())
                      .build()
              )
              .build()
      ),
      AgentCreateParams.Tool.ofCustom(
          BetaManagedAgentsCustomToolParams.builder()
              .type(BetaManagedAgentsCustomToolParams.Type.CUSTOM)
              .name("lookup_order")
              .description("Look up one order by its ID. Returns the status, the items, and the delivery date.")
              .inputSchema(
                  BetaManagedAgentsCustomToolInputSchema.builder()
                      .properties(
                          BetaManagedAgentsCustomToolInputSchema.Properties.builder()
                              .putAdditionalProperty("order_id", JsonValue.from(Map.of(
                                  "type", "string",
                                  "description", "The order ID from the ticket")))
                              .build()
                      )
                      .addRequired("order_id")
                      .build()
              )
              .build()
      )
  );
  ```

  ```php PHP
  use Anthropic\Beta\Agents\BetaManagedAgentsAgentToolset20260401Params;
  use Anthropic\Beta\Agents\BetaManagedAgentsAgentToolsetDefaultConfigParams;
  use Anthropic\Beta\Agents\BetaManagedAgentsAlwaysAllowPolicy;
  use Anthropic\Beta\Agents\BetaManagedAgentsAlwaysAskPolicy;
  use Anthropic\Beta\Agents\BetaManagedAgentsAutoPolicy;
  use Anthropic\Beta\Agents\BetaManagedAgentsCustomToolInputSchema;
  use Anthropic\Beta\Agents\BetaManagedAgentsCustomToolParams;
  use Anthropic\Beta\Agents\BetaManagedAgentsReadToolConfigParams;
  use Anthropic\Beta\Agents\BetaManagedAgentsWebFetchToolConfigParams;
  use Anthropic\Beta\Agents\BetaManagedAgentsWriteToolConfigParams;

  $tools = [
      BetaManagedAgentsAgentToolset20260401Params::with(
          type: 'agent_toolset_20260401',
          defaultConfig: BetaManagedAgentsAgentToolsetDefaultConfigParams::with(
              enabled: false,
              permissionPolicy: BetaManagedAgentsAlwaysAskPolicy::with(type: 'always_ask'),
          ),
          configs: [
              BetaManagedAgentsReadToolConfigParams::with(
                  enabled: true,
                  permissionPolicy: BetaManagedAgentsAlwaysAllowPolicy::with(type: 'always_allow'),
              ),
              BetaManagedAgentsWriteToolConfigParams::with(
                  enabled: true,
                  permissionPolicy: BetaManagedAgentsAutoPolicy::with(),
              ),
              BetaManagedAgentsWebFetchToolConfigParams::with(
                  allowedDomains: ['help.example.com'],
                  enabled: true,
                  permissionPolicy: BetaManagedAgentsAutoPolicy::with(),
              ),
          ],
      ),
      BetaManagedAgentsCustomToolParams::with(
          type: 'custom',
          name: 'lookup_order',
          description: 'Look up one order by its ID. Returns the status, the items, and the delivery date.',
          inputSchema: BetaManagedAgentsCustomToolInputSchema::with(
              properties: ['order_id' => ['type' => 'string', 'description' => 'The order ID from the ticket']],
              required: ['order_id'],
          ),
      ),
  ];
  ```

  ```ruby Ruby
  tools = [
    {
      type: "agent_toolset_20260401",
      default_config: {
        enabled: false,
        permission_policy: {type: "always_ask"}
      },
      configs: [
        {
          name: "read",
          enabled: true,
          permission_policy: {type: "always_allow"}
        },
        {
          name: "write",
          enabled: true,
          permission_policy: {type: "auto"}
        },
        {
          name: "web_fetch",
          enabled: true,
          allowed_domains: ["help.example.com"],
          permission_policy: {type: "auto"}
        }
      ]
    },
    {
      type: "custom",
      name: "lookup_order",
      description: "Look up one order by its ID. Returns the status, the items, and the delivery date.",
      input_schema: {
        type: "object",
        properties: {order_id: {type: "string", description: "The order ID from the ticket"}},
        required: ["order_id"]
      }
    }
  ]
  ```
</CodeGroup>

[代理更新](https://platform.claude.com/docs/zh-TW/managed-agents/agent-setup#update-semantics)會取代整個 `tools` 陣列，因此請傳送您想保留的每個項目。

代理更新只會套用到新的工作階段，因此也請檢查部署、列出此代理的代理，以及現有的工作階段：

* 部署會固定一個代理版本，因此請將每個部署指向新版本。
* 在 [`subagents.predefined_agents`](https://platform.claude.com/docs/zh-TW/managed-agents/multiagent-orchestration#list-the-subagents) 或 `workflows.predefined_agents` 中列出此代理的代理，會保留其固定的版本，因此也請更新該代理。
* 若要收緊已存在的工作階段，請[更新該工作階段的工具](https://platform.claude.com/docs/zh-TW/managed-agents/session-operations#updating-the-agent-configuration)。工作階段必須處於 `idle` 狀態，且更新會取代整個 `tools` 陣列。在多代理工作階段中，工作階段所執行代理的網頁工具上新的 `allowed_domains` 和 `blocked_domains` 清單也會套用到其他每個代理。它們會從每個代理的下一個回合開始套用。這些代理已啟用的工具和權限政策不會改變。若要變更這些設定，請更新每個代理，然後啟動新的工作階段。

也請將 MCP 伺服器和自訂工具限制在代理需要的範圍內：

* **MCP 伺服器：** MCP 工具集預設會啟用伺服器公開的每個工具。將 `default_config.enabled` 設為 `false` 並啟用指定的工具，讓伺服器之後新增的工具保持關閉。移除代理未使用的伺服器。請參閱 [MCP 連接器](https://platform.claude.com/docs/zh-TW/managed-agents/mcp-connector#configure-which-mcp-tools-are-available)。
* **自訂工具：** 由您的應用程式執行，權限政策不適用。請在您的應用程式中驗證每個呼叫的輸入，並限制該工具可以接觸的範圍。

## 讓不受信任的輸入遠離強大的工具

每當代理讀取不受信任的輸入（也就是您團隊以外的人可以撰寫的文字）時，請檢查它持有哪些工具和憑證。本節使用兩個術語：

* **不受信任的輸入：** 網頁、搜尋結果、客服工單、電子郵件、儲存庫檔案、上傳內容、MCP 伺服器結果，以及您轉送的終端使用者訊息。
* **強大的工具：** `bash`、`write`、`edit`、`web_fetch`、`web_search`、會寫入或傳送資料的 MCP 工具和自訂工具，以及任何使用憑證的工具。

不受信任輸入中的文字可能會指示代理使用它所持有的強大工具。客服代理會讀取工單，因此它只能透過自訂工具 `lookup_order` 存取您的訂單 API。您的應用程式會檢查該訂單是否屬於工單的寄件者。

| 代理讀取的輸入         | 它同時擁有的能力                                                                                                    | 應採取的做法                                                                                                                                                                                        |
| --------------- | ----------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 工單、電子郵件或上傳內容    | 帶有憑證的 `bash`                                                                                                | 以只做一件事的自訂工具取代 `bash`。如果代理必須保留 `bash`，請使用 `always_ask` 核准每個呼叫                                                                                                                                  |
| 網頁或搜尋結果         | 寫入檔案或變更記錄                                                                                                   | 關閉網頁工具，或將其限制為您營運或信任的網站                                                                                                                                                                        |
| MCP 結果或儲存庫檔案    | 會寫入的 MCP 工具                                                                                                 | 將 MCP 工具集保持在 `always_ask`，並僅啟用代理需要的工具                                                                                                                                                         |
| 已掛載的 GitHub 儲存庫 | 任何工具                                                                                                        | 僅掛載您信任的儲存庫。擁有 `read` 的代理會將儲存庫 `.claude/skills` 目錄中的技能載入為代理指示，且沒有審查步驟。請參閱[從 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/memory#attach-a-memory-store-to-a-session) | 除非代理必須寫入，否則請以 `read_only` 附加儲存區。預設值為 `read_write`，之後的工作階段會將已儲存的文字視為受信任的記憶讀取                                                                                                                   |

在雲端環境中，使用 `read` 讀取檔案也可能將 `CLAUDE.md` 和 `AGENTS.md` 檔案載入為指示。它們會從該檔案所在的目錄及其上層目錄載入，直到沙箱的工作目錄為止。它們以 `@` 加上路徑所參照的檔案（例如 `@docs/setup.md`）也會被載入，最多可達五層參照。參照可以指向沙箱中的任何位置，例如 `@/etc/hosts`。除了停用 `read` 之外，沒有任何設定可以關閉此行為，因此請將您團隊以外的人可以撰寫的儲存庫、套件或封存檔視為不受信任的輸入。

當代理必須讀取不受信任的輸入並同時採取行動時，本指南建議以下三種設計之一：

* **將讀取與行動分開。** 在一個多代理工作階段中，由[主導代理](https://platform.claude.com/docs/zh-TW/managed-agents/multiagent-orchestration#list-the-subagents)將任務分派給負責讀取網路的擷取者，以及負責變更檔案或記錄的撰寫者。
* **為代理提供一個範圍狹窄的自訂工具。** 由您的應用程式執行該工具、檢查其輸入並持有憑證。客服代理使用的是這種設計，而非分離設計。請參閱[回應使工作階段暫停的工具呼叫](https://platform.claude.com/docs/zh-TW/managed-agents/events-and-streaming#answer-tool-calls-that-pause-the-session)。
* **讓人員參與流程。** 在強大的工具上使用 `always_ask`，讓人員核准每個呼叫。

分離設計使用三個代理：

| 代理              | 讀取               | 持有                                                     | 傳遞                   |
| --------------- | ---------------- | ------------------------------------------------------ | -------------------- |
| 主導者（工作階段所執行的代理） | 您的訊息，以及其他代理傳回的內容 | 沒有內建工具。其 `subagents.predefined_agents` 清單指定了擷取者和撰寫者    | 給每個代理的任務             |
| 擷取者             | 網頁和搜尋結果          | 僅有 `web_fetch` 和 `web_search`，且各自設定了 `allowed_domains` | 簡短的結果，格式依您在其系統提示中的要求 |
| 撰寫者             | 來自主導者的任務         | 會寫入檔案、執行命令或變更記錄的工具，設為 `auto` 或 `always_ask`。沒有網頁工具     | 其結果                  |

擷取者的結果是由不受信任的網頁建構而成，而主導者可能會將其文字傳遞給撰寫者。請在撰寫者的工具上保持 `auto` 或 `always_ask`。擷取者仍可能將其讀取的部分內容傳送到其 `web_fetch` 清單上的網站，並透過查詢傳送給搜尋服務提供者。

同一個多代理工作階段中的代理會[共用沙箱](https://platform.claude.com/docs/zh-TW/managed-agents/multiagent-orchestration#how-it-works)、其檔案以及保管庫憑證，因此這種分離只會區隔它們的工具和對話。若要更強的分離，請使用兩個具有各自環境和保管庫的工作階段。讓您的應用程式在兩個工作階段之間只傳遞固定欄位，例如訂單 ID。

## 設定限制和停止方式

在建立每個工作階段時設定預算，並事先決定如何停止代理。

| 控制項                                                                                                                   | 功能                                                                                                                                                                                                                                                          |
| --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 工作階段預算                                                                                                                | 以公開定價計算的支出上限。達到上限時，工作階段和每個[執行緒](https://platform.claude.com/docs/zh-TW/managed-agents/session-threads)都會暫停。進行中的請求可以完成，其工具呼叫仍會執行，因此支出可能超過上限。請參閱[當工作階段達到預算時](https://platform.claude.com/docs/zh-TW/managed-agents/budgets#when-a-session-reaches-its-budget) |
| 部署預算                                                                                                                  | 相同的上限，套用到部署所啟動的每個工作階段                                                                                                                                                                                                                                       |
| [`user.interrupt` 事件](https://platform.claude.com/docs/zh-TW/managed-agents/events-and-streaming#interrupt-the-agent) | 立即停止模型回應。執行中的工具呼叫可能會先完成。工作階段會進入 `idle`，除非有工作流程執行使其保持 `running`，並在您傳送下一則訊息時繼續。中斷不會結束任何工作流程執行                                                                                                                                                                 |
| 封存或刪除工作階段                                                                                                             | 封存會保留歷史記錄並阻擋新事件。刪除會移除記錄、事件和沙箱                                                                                                                                                                                                                               |
| 暫停或封存部署                                                                                                               | 暫停會停止新的排程執行，但仍允許手動執行。封存會永久結束排程。已在執行中的工作階段會繼續執行                                                                                                                                                                                                              |
| 封存或刪除保管庫或憑證                                                                                                           | 無需重新啟動即可從執行中的工作階段移除機密。請預留一些延遲時間。工作階段會繼續執行，因此也請中斷它們。代理已使用該機密擷取的權杖會留在沙箱中                                                                                                                                                                                      |

若要停止執行中的代理，請依照以下步驟操作：

1. 單獨傳送 `user.interrupt`。
2. 對於排程代理，也請暫停部署，以免啟動新的排程執行。若要永久結束排程，請封存部署。
3. 如果金鑰可能已外洩，請在核發該金鑰的服務端輪替它。
4. 如果代理有開啟中的工作流程執行，也請傳送一則 `user.message` 要求它停止這些執行，因為中斷不會結束任何執行。如需應先取消的工具呼叫，請參閱[在有開啟的執行時中斷工作階段](https://platform.claude.com/docs/zh-TW/managed-agents/workflow-runs#interrupt-a-session-with-runs-open)。
5. 等待工作階段進入 `idle`。執行中的工作階段無法被封存或刪除。
6. 封存工作階段以保留其歷史記錄。當您不再需要歷史記錄時，請將其刪除。

中斷不會復原代理已經執行或傳送的內容。封存代理不會停止其執行中的工作階段。

預算的 `max_list_cost.amount` 是以字串表示的美分整數，因此 `"125"` 代表 $1.25。請參閱[在建立工作階段時設定預算](https://platform.claude.com/docs/zh-TW/managed-agents/budgets#set-a-budget-at-session-creation)。

您無法為建立時未設定預算的工作階段新增預算。若要變更或移除上限，請參閱[恢復達到預算的工作階段](https://platform.claude.com/docs/zh-TW/managed-agents/budgets#resume-a-session-at-its-budget)。移除工作階段的上限後，您就無法再設定新的上限。

預算會限制支出，但不會限制代理在達到上限之前所做的事。若要區隔不同信任等級的工作負載，請使用不同的[工作區](https://platform.claude.com/docs/zh-TW/manage-claude/workspaces)。為每個工作負載提供範圍限定於單一工作區的 API 金鑰，因為可存取多個工作區的金鑰可以在其中任何一個工作區中執行操作。

請參閱[工作階段預算](https://platform.claude.com/docs/zh-TW/managed-agents/budgets)、[工作階段操作](https://platform.claude.com/docs/zh-TW/managed-agents/session-operations#archiving-a-session)和[排程部署](https://platform.claude.com/docs/zh-TW/managed-agents/scheduled-deployments#managing-deployment-lifecycle)。

## 後續步驟

<CardGroup cols={2}>
  <Card title="雲端環境設定" icon="cloud" href="https://platform.claude.com/docs/zh-TW/managed-agents/environments">
    網路模式、允許的主機和套件管理器。
  </Card>

  <Card title="權限政策" icon="check" href="https://platform.claude.com/docs/zh-TW/managed-agents/permission-policies">
    核准政策和確認請求。
  </Card>

  <Card title="使用 vault 進行驗證" icon="lock" href="https://platform.claude.com/docs/zh-TW/managed-agents/vaults">
    憑證類型、注入位置和輪替。
  </Card>

  <Card title="工作階段預算" icon="coins" href="https://platform.claude.com/docs/zh-TW/managed-agents/budgets">
    上限、在達到預算時恢復，以及部署上的預算。
  </Card>
</CardGroup>
