Gemini API 的 Managed Agents 可以接自己的 sandbox 了
Google AI Studio 在 2026-11-11(美國時間)宣布,Gemini API 的 managed agents 可以「bring your own sandbox」,改用自架的環境。原本 agent 的工具都跑在 Google 代管的 Linux sandbox,現在可以放到自己控制的機器上。
怎麼接
官方文件寫的三個步驟:
- 呼叫
POST /v1beta/environments,帶{"mode": "self_hosted"},拿到環境id和一組只給一次的environment_key。 - 在自己的 sandbox 裡,用那組 key 跑
gemini-api environments connect(開源的google-gemini/gemini-api-cli)。 - 呼叫
interactions.create時,把環境id放進environment。
sandbox 是用對外 HTTPS 連到 Google,不需要開任何對內的防火牆 port。
要注意的地方
- 代管 sandbox 才有的選項(
sources、network、env、/files快照)不能用在自架環境,帶了會回400 INVALID_ARGUMENT。 - runtime 也能跑在 Docker 或 rootless Podman 裡;測試時可以直接在本機跑,但本機模式下
execute_bash會直接在主機上執行,除非加--disable-bash。 - 文件列了幾個 sandbox 供應商的接法範例,例如 Google Cloud Run、Cloudflare Sandbox、Daytona、E2B、Fly.io、Modal、Vercel Sandbox。
- environments 和 managed agents 都還在 preview,功能和 schema 可能會改。
Gemini API Managed Agents can now run tools in your own sandbox
On 2026-11-11 (US time), Google AI Studio announced that Gemini API managed agents can now “bring your own sandbox” with self-hosted environments. Agent tools used to run only in Google-hosted Linux sandboxes; now they can run on infrastructure you control.
How to connect
The docs list three steps:
- Call
POST /v1beta/environmentswith{"mode": "self_hosted"}to get an environmentidand a one-timeenvironment_key. - Inside your sandbox, run
gemini-api environments connect(from the open-sourcegoogle-gemini/gemini-api-cli) with that key. - Pass the environment
idinenvironmentwhen callinginteractions.create.
The sandbox connects to Google over outbound HTTPS and needs no inbound firewall ports.
Things to know
- Hosted-sandbox options (
sources,network,env, and/filessnapshots) don’t apply to self-hosted environments, which reject them with400 INVALID_ARGUMENT. - The runtime can also run in Docker or rootless Podman. For testing it can run locally, but local mode runs
execute_bashdirectly on the host unless you pass--disable-bash. - The docs include example setups for sandbox providers such as Google Cloud Run, Cloudflare Sandbox, Daytona, E2B, Fly.io, Modal, and Vercel Sandbox.
- Environments and managed agents are in preview, and features and schemas may change.