無伺服器沙盒 REST 與閘道 API 參考(預覽版)

Azure 容器執行個體 中的無伺服器沙盒有三個 API。 父 AI 代理群組是 Azure Resource Manager 的資源,您透過群組的端點管理其內部的沙盒。

API Endpoint Authorization
AI 代理群組 API https://management.azure.com Microsoft Entra ID token for Azure Resource Manager, and Azure RBAC on the AI agents group
沙盒管理 API 當endpointconnect動作回傳時 Authorization: Bearer <accessToken>,當 ,accessTokenconnect作用回傳
沙盒閘道 API 在addressconnectionString沙盒中,連接埠443 authorization: Bearer <token>,在tokenconnectionString沙盒中

所有請求皆使用 API 版本 2026-08-01-preview。

AI 代理群組 API

AI 代理程式群組 API 是該Microsoft.ContainerInstance/AIAgentsGroups資源類型的 Azure Resource Manager REST API。 此表中的 URL 相對於 https://management.azure.com/subscriptions/{subscriptionId}。

運算 方法與網址
建立或更新 AI 代理程式群組 PUT /resourceGroups/{resourceGroup}/providers/Microsoft.ContainerInstance/AIAgentsGroups/{agentsGroup}
組建 AI 代理團隊 GET /resourceGroups/{resourceGroup}/providers/Microsoft.ContainerInstance/AIAgentsGroups/{agentsGroup}
在資源群組中列出 AI 代理程式群組 GET /resourceGroups/{resourceGroup}/providers/Microsoft.ContainerInstance/AIAgentsGroups
在訂閱中列出 AI 代理群組 GET /providers/Microsoft.ContainerInstance/AIAgentsGroups
刪除 AI 代理群組 DELETE /resourceGroups/{resourceGroup}/providers/Microsoft.ContainerInstance/AIAgentsGroups/{agentsGroup}
連接至 AI 代理群組 POST /resourceGroups/{resourceGroup}/providers/Microsoft.ContainerInstance/AIAgentsGroups/{agentsGroup}/connect

建立、更新與刪除 AI 代理群組是長期運作的作業。 發送 GET 請求直到 properties.provisioningState 為 Succeeded。 刪除 AI 代理群組也會刪除其沙盒。

AI 代理程式群組屬性

Property Description
location AI 代理群組的 Azure 區域。
tags 資源標籤。
identity AI 代理程式群組的管理身份,以標準 Azure Resource Manager identity 格式呈現,且為 typeuserAssignedIdentities。
properties.networkProfile.subnets[].id 被委派給 Microsoft.ContainerInstance/AIAgentsGroups的子網路資源 ID 。 建立群組時設定。 您稍後無法加以變更。
properties.identityProfile.federatedIdentityCredential 代理 身份 藍圖所設定的管理身份主 ID、信任,或 SystemIdentity。
properties.identityProfile.imageRegistryCredential 拉取影像的受管理身份的主要 ID,或 SystemIdentity。
properties.identityProfile.sandboxCredential 沙箱可以使用的受管理身份主體 ID 陣列,或 SystemIdentity。
properties.agentFabricResourceId 同一訂閱與區域內 Azure Agent Grid 資源Microsoft.NetworkSecurity/agentFabrics的資源 ID()(請參閱 Agent Grid 區域可用性)。 建立群組時設定。 你之後無法更改它,也無法與 networkProfile合併。
properties.provisioningState Read-only. AI 代理程式群組的配置狀態。
properties.sandboxGroupUniqueId Read-only. 為 AI 代理程式群組產生的穩定唯一識別碼。
properties.managedResourceGroupId Read-only. 為 AI 代理程式群組配置的管理資源群組的資源 ID。
properties.storageAccountResourceId Read-only. 已配置用於快照、儲存與還原的管理儲存帳戶的資源 ID。

要求範例︰

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.ContainerInstance/AIAgentsGroups/myAgentsGroup?api-version=2026-08-01-preview

{
  "location": "centralus",
  "identity": {
    "type": "UserAssigned",
    "userAssignedIdentities": {
      "/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity": {}
    }
  },
  "properties": {
    "networkProfile": {
      "subnets": [
        { "id": "/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/myVnet/subnets/sandbox-subnet" }
      ]
    },
    "identityProfile": {
      "federatedIdentityCredential": "<identity-principal-id>"
    }
  }
}

Connect 回應

此 connect 動作會回傳 AI 代理程式群組的沙盒管理端點,以及其短暫的存取權杖:

{
  "endpoint": "https://<group-endpoint-host>/subscriptions/{subscriptionId}/resourcegroups/myResourceGroup/providers/Microsoft.ContainerInstance/<group-path>",
  "accessToken": "<access-token>",
  "notAfter": "2026-11-04T10:30:00Z"
}

該 endpoint 值已包含該群組的資源路徑。 直接使用回傳的 endpoint URL。 當存取權杖在 notAfter 該時到期時,請再次呼叫 connect 。

沙盒管理 API

沙盒管理 API 是 AI 代理群組的 REST API。 此表格中的 URL 是相 endpoint 對於動作 connect 所回傳的 URL 的。 加入 ?api-version=2026-08-01-preview 每個請求。

運算 方法與網址 要求本文
建立一個沙盒 PUT /sandboxes/{sandbox} 沙盒屬性
弄個沙盒 GET /sandboxes/{sandbox} None
列出沙盒 GET /sandboxes None
刪除沙盒 DELETE /sandboxes/{sandbox} None
停止沙盒 POST /sandboxes/{sandbox}/stop None
啟動已停止的沙盒 POST /sandboxes/{sandbox}/start None
重新啟動沙盒 POST /sandboxes/{sandbox}/restart None
調整沙盒大小 POST /sandboxes/{sandbox}/resize { "cpu": <cores>, "memoryInGB": <GiB> }
儲存沙盒快照 POST /sandboxes/{sandbox}/saveSnapshot { "snapshotName": "<name>" }
列出快照 GET /snapshots None
刪除快照集 DELETE /snapshots/{snapshot} None

沙盒建立是非同步的。 發送 GET 請求直到 properties.provisioningState , Succeeded然後呼叫 WaitForReady 閘道的方法,等待訪客程式正在執行。

清單操作會回傳陣 value 列,並在有更多結果時回 nextLink 傳 URL。

動作 stop 是非同步的。 沙盒會移動到 Stopping ,然後再移動到 properties.provisioningStateStopped 。 只有在沙盒到達 Stopped後才呼叫start。 停止的沙盒沒有 connectionString,因此在之後start再呼叫GET /sandboxes/{sandbox}一次以取得新的 連接字串。

與resizesaveSnapshot動作需要持續運作的沙盒,並回傳一個操作endpoint與 accessToken。 若要等待操作完成,請使用該令牌呼叫 WaitForOperationComplete 該端點閘道的方法。 儲存快照會暫停來源沙箱並匯出其記憶體、檔案系統及執行階段狀態。

沙盒屬性

Property Description
location AI 代理群的區域。
tags 沙盒標籤。
properties.image 可選的 OCI 影像參考或公開映像別名,以初始化沙盒根檔案系統。 省略使用預設訪客環境。 與 snapshot互斥。
properties.snapshot 要 還原 沙箱的同一 AI 代理群組中的快照名稱。 與 image 和 environmentVariables 互斥。
properties.guestOs linux (預設)。
properties.architecture amd64 (預設)。
properties.resources.cpu CPU 核心數(支援分數值)。 固定大小使用純量數,或使用具有 initial、 、 minmax 和 值 (min <= initial <= max) 的物件作為可伸縮沙盒。 在指定界限時,兩者皆cpumemory為必填。
properties.resources.memory 記憶體單位為 GiB(支援分數值)。 固定大小使用純量數,或使用具有 initial、 、 minmax 和 值 (min <= initial <= max) 的物件作為可伸縮沙盒。
properties.resources.disk 以 GB 為單位的磁碟大小。
properties.environmentVariables 可選的預設環境變數陣列({ "name": "<name>", "value": "<value>" }或{ "name": "<name>", "secureValue": "<secret>" })套用於沙盒中的每個execshell程序。 支援最多 100 個項目,總容量為 64 KB。 僅可創建;secureValue為僅寫入且在 上GET省略;不可與 結合。snapshot
properties.dataDisks 附加於沙盒的可選管理資料磁碟陣列({ "id": "<managed-disk-resource-id>" })。
properties.trustedCaCertificates 可選擇加入 root 或中介 CA 憑證{ "format": "pem", "value": "<base64-pem>" }的陣列,以新增至沙盒信任儲存庫。
properties.diagnostics 可選的診斷設定({ "logAnalytics": { "workspaceId": "<guid>", "workspaceKey": "<key>" } }),將容器stdout/stderr傳送至 Log Analytics 工作區。 僅可創建; workspaceKey 僅為寫入。
properties.confidentialComputeProperties.ccePolicy 基於 Base64 編碼的 CCE 機密 沙盒政策。 目前不支援 peerSandboxProfile、 或 attachToAgentFabric虛擬網路整合(networkProfile)。
properties.peerSandboxProfile 飛 地 預算,以整數為 cpu (1-64)和 memoryInGB (1-256)。 僅可創建;無法與confidentialComputeProperties或/resourcesminmax界限結合。
properties.agentIdentities 一個包含 和 agentBlueprintId的代理程式身份項目agentId的陣列。
properties.attachToAgentFabric true 將沙盒附加到 AI 代理群組的 代理網格 。 無法與 confidentialComputeProperties合併,且無法在創建後從 true 變更 false 。
properties.harvest 可選的布林值(true 或 false)表示沙盒是否以收割容量運作。
properties.dnsConfig 沙盒的 DNS 設定(servers, searches, options)。 預設為 Azure DNS (168.63.129.16)。
properties.provisioningState Read-only. 沙盒的配置狀態。
properties.targetState Read-only. Active,或 Stopped 是在行動之後 stop 。
properties.resources.cpu.current,properties.resources.memory.current Read-only. 可伸縮沙盒目前的資源分配。
properties.connectionString Read-only. address沙盒閘道的 and token 為 ,形式為 address=<host>;token=<token>;token_type=bearer。 把它當成秘密。
properties.instanceView.errorMessage Read-only. 為什麼沙盒會失敗,何時失敗。

要求範例︰

PUT {endpoint}/sandboxes/sandbox1?api-version=2026-08-01-preview
Authorization: Bearer {accessToken}
Content-Type: application/json

{
  "location": "centralus",
  "properties": {
    "image": "mcr.microsoft.com/azurelinux/base/core:3.0",
    "resources": {
      "cpu": 1,
      "memory": 2
    }
  }
}

快照名稱

快照名稱必須為 DNS 標籤:由 1-63 個小寫字母、數字或連字號組成,且以字母或數字開頭與結尾。

沙盒閘道 API

沙箱閘道 API 即為 gRPC 服務 aci.sandboxgateway.SandboxGatewayService。 用它在一個持續運作的沙盒裡工作。

呼叫閘道器的方法如下:

  1. 從沙盒管理 APIGET {endpoint}/sandboxes/{sandbox} () 取得沙箱的 。connectionString 其格式為 address=<host>;token=<token>;token_type=bearer。
  2. 用 TLS 連接 <host> 443 埠。
  3. 將每個呼叫Bearer <token>的元資料中authorization,以 為 的方式傳送該令牌。 閘道會從 token 來識別沙盒,因此請求不會有沙盒名稱。

從 sandboxgateway.proto為你的語言產生一個客戶端。 關於 C# CLI 的教學與使用範例,請參閱 《從 sandboxgateway.proto 建立 C# CLI 》及 《快速入門:建立你的第一個無伺服器沙盒》。

Method 類型 請求欄位 Description
WaitForReady Unary timeout_seconds 等沙盒準備好再說。 回傳 、 current_state,以及當主機回報時,回傳ready啟動時間。
GetSandbox Unary None 取得沙盒的定義與目前狀態。
GetLogs Unary tail、level、timestamps、cursor 讀取執行中沙盒的日誌緩衝區。 回傳 entries、 next_cursor、 gap_detected及 has_more。
ExecSandbox Unary command、args、working_directory、environment、timeout_seconds、user 在沙盒裡執行指令。 回傳 exit_code、 stdout、 stderr及 timed_out。
InteractiveShell 雙向流 start(shellargs, input, initial_colsenvironmentinitial_rowsuserworking_directory, , ), non_terminal則 , 或 window_sizesignal 在沙盒中開啟互動式或串流式 shell 工作階段。
ExecContainer 雙向流 start(container_idcmd, input, environmentttyworking_directoryinitial_rowsstdin, , ), initial_cols則 , 或 window_sizesignal 在沙盒中的容器中執行互動式指令。
PortForward 雙向流 start(port, ), host則或dataclose 將 TCP 連線轉寄至沙箱中的某個連接埠。
WriteFile Unary path、、 content、 mode、 append、 container_id 在沙盒或容器container_id中寫入檔案()。
WriteFileStream 用戶端串流 start (path, mode, append, , container_id), 則 content 將位元組串流到檔案,且不會將整個檔案緩衝到記憶體中。
ReadFile 伺服器串流 path、offset、max_chunk_size、container_id 把檔案分成區塊閱讀。 每個回應皆有 content、 next_offset、 eof及 。
DownloadFromBlobstore Unary source_sas_url、path、mode、container_id 從 Azure Blob 儲存體 直接下載 blob 到 sandbox 或使用 SAS URL 的容器中。
DownloadFileToUrl Unary path、destination_sas_url、container_id 使用 SAS URL 直接從沙箱或容器上傳檔案至 Azure Blob 儲存體。
CreateDirectory Unary path、mode、container_id 建立目錄及其父目錄。
ListDirectory Unary path,container_id 列出目錄。
Move Unary source、destination、overwrite、container_id 移動或重新命名檔案或目錄。
DeleteFile Unary path、recursive、container_id 刪除檔案或目錄。
SearchContent Unary path、pattern、is_regex、case_sensitive、max_results、container_id 搜尋檔案中的文字。
ReplaceContent Unary path、pattern、replacement、is_regex、case_sensitive、container_id 替換檔案中的文字。
BindMount Unary source、target、readonly、recursive 將沙盒中的路徑綁定掛載到另一條路徑。
ConnectIscsi Unary target_iqn、portal、port、sessions、timeout_seconds、format_if_empty 將沙盒訪客連線至 iSCSI 目標。 回傳 session_ids、 devices、 portal_address及 multipath_devices。
WatchChanges 伺服器串流 path,recursive 將變更串流至路徑直到通話結束。
PauseSandbox,ResumeSandbox Unary None 暫停或繼續沙盒遊戲。
WaitForOperationComplete Unary timeout_seconds 請等待執行較長時間的操作,例如快照或調整大小,完成。 用操作端點和 token 呼叫它。 返回 complete 和 terminal_state。

在 protobuf 訊息的 JSON 表示中,欄位名稱使用小寫 ,例如 timeoutSeconds,欄位bytescontent則使用 Base64 編碼。

Enclave 主機橋接 API

在具有 enclave 預算的properties.peerSandboxProfile父沙箱內部,訪客會透過 vsock(AF_VSOCKhostCID 2、port5090)與主機的 gRPC 服務aci.hostbridge.peersandbox.v1.PeerSandboxService通訊,以管理 enclave 與 vsock 埠轉發。 如需完整 peersandbox.proto 定義與 sandboxctl CLI 操作流程,請參閱 教學:在無伺服器沙箱隱居中執行敏感工作負載。

Method 類型 請求欄位 Description
CreatePeer Unary name、image、cores、memory_in_gb 在父沙箱的 peerSandboxProfile 預算內建立一個 enclave 微型虛擬機。
GetPeer Unary name 取得一個飛地目前的狀態與資源分配。
ListPeers Unary None 列出父沙箱的所有 encleves 以及剩餘的預算(cores, , memory_in_gbused_coresused_memory_in_gb, )。
StartPeer,StopPeer Unary name 啟動一個已停止的據點,或停止正在執行的據點。
DeletePeer Unary name 刪除一個飛地。
ExecPeer Unary name、command、args、working_directory、environment、timeout_seconds 在一個 enclave 裡執行一個指令。 回傳 exit_code、 stdout、 stderr及 timed_out。
ShellPeer 雙向流 start(name, , , environmentworking_directory, rows, ), cols則 input, window_size, 或 shellsignal 在一個 enclave 中開啟一個互動式 TTY shell 工作階段。
CreateForward Unary peer、to_parent、target_port、listen_port 在父沙箱與 enclave 之間開啟一個 vsock 埠轉發。 返回 id 以及 listen_port 在主機上 (CID 2)。
ListForwards Unary None 列出呼叫者建立的啟用 vsock 埠轉發。
DeleteForward Unary id 刪除 vsock 埠轉發。

在沙盒中運行容器與 pod

每個沙盒都包含一個容器執行環境。 你可以透過 Kubernetes 容器執行介面(CRI) 透過沙箱閘道,在與其他閘道方法相同的閘 address 道上拉取映像檔,並啟動 token pod 和容器。 這些 pod 和容器運行在沙盒的微型虛擬機內,因此沙盒仍然是它們的硬體隔離邊界。

若要在帶有終端機的容器中執行互動式指令,請使用 ExecContainer 沙盒閘道的方法。 當你刪除沙盒時,運行在沙盒內的任何 pod 和容器也會被刪除。

在沙箱中掛載 Azure 儲存體

您可以從沙箱內部掛載 Azure 檔案儲存體 共享與 Azure Blob 儲存體 容器,例如使用以下ExecSandbox方法。 沙盒需要對儲存帳號的網路存取,映像則需要掛載工具。

儲存體 如何安裝 圖片中必須
Azure 檔案儲存體 將該份額掛載於 SMB 上,並 。mount -t cifs 如需更多資訊,請參閱在 Linux 上掛載 SMB Azure 檔案共享。 cifs-utils
Azure Blob 儲存體 使用 BlobFuse2 掛載容器。 如需更多資訊,請參閱《如何在 Linux 上使用 BlobFuse2 掛載 Azure Blob 儲存體 容器》。 blobfuse2 以及 FUSE

為避免沙箱中的儲存帳戶金鑰,請為沙箱設定代理 程式識別碼,並授予該身份對儲存帳戶的存取權。

Troubleshoot

徵兆 Resolution
建立 AI 代理群組失敗時,出現 404 Not Found ("code": "InvalidResourceType"、 "message": "The resource type could not be found in the namespace 'Microsoft.ContainerInstance' for api version '2026-08-01-preview'"),或該群組的 provisioningState 群組為 Failed 您的訂閱尚未設定無伺服器沙盒配額。 要解決此錯誤,請在 Azure 入口網站提交 容器執行個體 配額支援請求,並將配額詳情中的配額類型設為 AIAgentsGroups - StandardCores (Preview)。 在您的配額申請獲批准後,請重新註冊資源 Microsoft.ContainerInstance 提供者(az provider register --namespace Microsoft.ContainerInstance --wait)。
AI 代理程式群組建立或請求失敗,導致授權錯誤 請使用具有 AI 代理程式群組存取權限的帳戶登入,並確保您的租戶(az ad sp create --id 1eeacc2b-ec4a-4b1e-977a-2b5fef2131c6)中存在計算沙盒群組服務主體(1eeacc2b-ec4a-4b1e-977a-2b5fef2131c6),且訂閱中具有貢獻者、Azure 部署堆疊擁有者及儲存 Blob 資料貢獻者角色,以便能配置受管理的資源群組與儲存帳戶。 如果您的配額請求最近已獲核准,請重新註冊資源 Microsoft.ContainerInstance 提供者,並等待角色指派完成。
沙盒管理請求失敗 401 Unauthorized 存取權杖已過期。 再叫 connect 一次行動。
閘道呼叫因授權錯誤而失敗 重新取得 connectionString 沙盒,並使用它的標記。
沙盒建立失敗 Allocation failed permanently 請求已無主機容量可用。 若要申請更多容量,請在 Azure 入口網站提交 容器執行個體 配額支援請求(在配額詳細資料中選擇 AIAgentsGroups - StandardCores (Preview)配額類型),或建立 Azure 支援 請求。
resize 失敗並顯示 BadRequest 目標位於沙盒的 and max 值之外min,或沙盒擁有固定資源。
saveSnapshot 失敗並顯示 BadRequest 沙盒未執行、快照名稱不是有效的 DNS 標籤,或沙盒有 enclave 預算(peerSandboxProfile)。
沙盒無法取得 Azure 資源的令牌 請確認你建立沙盒時已使用 agentIdentities,且藍圖信任 AI 代理程式群組的受管理身份。