explainx.ai350K+ learn from us
TrendingAI News TodayPathwaysSkills
Pricing
explainx.ai

Upskill in AI — 16 free pathways, live workshops & bootcamps, and 50+ courses from practitioners. Plus the skills, tools, and MCP servers to practice on.

follow us

follow on google

Add explainx.ai as a preferred source

corporate training

support@explainx.ai

get started

Find your pathTake Free Evaluation

community

Join the community

learn

mind: share how you thinkpathways — start freeworkshopsbootcampscoursescompare Explainxcertificationsmock testsexplainx universitycorporate traininglearn skills & mcp

discover

skillsmcp serversexplainx mcpestacktoolsmdx readeragentsllmsdesignsdictionarypeopleagi trackerfelony benchranks

company

aboutvisionmissionteaminstructorsteach on explainxpartnershipscommunityhackathonscareers

content

daily AI newsstate of AI — live resultsblogreleasespromptsgeneratorsresource libraryfor LLMsexplainx.ai kids

solutions

all solutionsdeveloper upskillingmarketing upskillingproduct manager upskillingleadership upskilling

newsletter · weekly

Get AI news, tools, and insights in your inbox.

supportcontactprivacytermsdata rightshow we create contentsubmission guidelines

© 2026 AISOLO Technologies Pvt Ltd

explainx.ai

On this page

  • TL;DR
  • Why self-hosted sandboxes matter now
  • Architecture: connect vs poll plus serve
  • Tool surface inside the worker
  • Partner reference workers
  • What stays on Google
  • CLI commands to know
  • Security checklist when you turn this on
  • Cost and performance expectations
  • How to try without production traffic
  • Comparison with other managed agent stacks
  • When to pick self-hosted Gemini environments
  • Interactions with Antigravity and Deep Research
  • Migration path from hosted-only agents
  • Data residency checklist (honest version)
  • Failure modes engineers report in similar systems
  • Observability hooks
  • Enterprise procurement talking points
  • Related reading
← Back to blog

explainx / blog

Gemini Managed Agents Self-Hosted Sandboxes: Run Shell Tools in Your Runtime

Google Gemini, AI Agents, Agent Security, Sandboxing, Developer Tools

Part of Google Gemini and DeepMind

Google documents Self-Hosted Environments for Gemini managed agents via gemini-api CLI, with partner workers on Modal, E2B, Cloudflare, and more.

Nov 11, 2026·8 min read·Yash Thakker
add explainx.ai
go deep
Gemini Managed Agents Self-Hosted Sandboxes: Run Shell Tools in Your Runtime

Google documented Self-Hosted Environments for Gemini managed agents so built-in bash and file tools can run in compute you control, while the Interactions API still orchestrates model turns from Google infrastructure. The reference implementation lives in the Apache-2.0 gemini-api CLI under docs/self-hosted/README.md.

If you already read Gemini managed agents Files and Credentials APIs, this release completes the picture: secrets and files were already designed to avoid living in the model context; execution locality now joins that stack.

Daily briefFrom Yash · 350K+ students taught

Catch up on AI

One AI story explained in plain English, plus one thing to try. Every day, free. Unsubscribe anytime.

TL;DR

table · 2 cols
LayerWho runs it (self-hosted mode)
Model inference and planningGemini API
Tool selection and agent loopGoogle managed agent runtime
execute_bash, file edits, grepYour worker container or VM
Base image, egress, idle cleanupYou or your sandbox vendor
Model token billingGoogle per API pricing

Why self-hosted sandboxes matter now

Managed agent orchestration on Google APIs with tool execution in your own runtimeManaged agent orchestration on Google APIs with tool execution in your own runtime

Managed agents were attractive because one API call spun up an Ubuntu sandbox with Python and Node. That speed collides with three production walls:

  1. GPU or custom packages you cannot fit in Google default image timing.
  2. Compliance that demands specific microVM vendors or private VPC routing.
  3. Cost when long-running environments need your reserved capacity instead of preview compute.

Self-hosted mode does not remove Google from the loop. It moves syscall risk to infrastructure you audit.

Our agent sandbox comparison guide maps the vendor landscape this feature plugs into.

Architecture: connect vs poll plus serve

Self-hosted workers attached to customer-controlled compute instead of Google preview VMsSelf-hosted workers attached to customer-controlled compute instead of Google preview VMs

Google documents two topologies in the self-hosted README.

Single-worker connect

A worker inside your container calls gemini-api environments connect with:

  • --environment-key scoped to one environment
  • --root-dir confining file tools
  • --workdir for relative paths

The worker polls POST /v1beta/environments:leaseInteractions and executes tool calls locally.

Key hygiene: create the environment with your project GEMINI_API_KEY, but inject only GEMINI_ENVIRONMENT_KEY into the worker. Google states the environment key is shown once at creation.

Split poll + serve

For Kubernetes or Agent Substrate clusters, a trusted poller holds API keys while untrusted workers receive only a short-lived lease_token. Workers run gemini-api environments serve with zero API keys inside the sandbox.

That matches how security teams wanted OpenAI Agents API self-hosted sandboxes documented: separate control plane from execution plane.

Tool surface inside the worker

Google lists built-ins executed locally:

  • execute_bash
  • view_file / read_file
  • write_to_file / write_file
  • replace_file_content / edit_file
  • list_dir, grep_search, find_by_name

Those names align with the Antigravity harness described in AI Studio agent docs. Self-hosted mode does not add new tools; it relocates them.

Partner reference workers

The README directory links deployment manifests for:

  • E2B
  • Modal
  • Daytona
  • Fly.io
  • Google Cloud
  • Cloudflare
  • Vercel

Each implements the environment protocol: authenticate, receive execution requests, return stdout and file deltas.

For Cloudflare specifically, pair this with Sandbox SDK 1.0 agent patterns. For Google Cloud isolation primitives, see Google Cloud Agent Sandboxes five isolation lessons.

What stays on Google

Google AI Studio agent documentation still states managed agents run in preview with:

  • Default 7-day environment lifetime after inactivity
  • Outbound network unless you set allowlists
  • Credentials injected at egress proxy, not inside sandbox memory

Self-hosted workers inherit your network policy, but Interactions traffic still transits the Gemini API. Treat compliance as joint: log what the worker returns upstream.

CLI commands to know

From the gemini-api README:

table · 2 cols
CommandPurpose
gemini-api environments createRegister self_hosted environment
environments connectSingle-process worker
environments pollControl-plane poller
environments serveIsolated executor with lease token
environments files uploadStage inputs before a run

Agents you already run — Codex, Claude Code, Antigravity — can shell out to the same binary, similar to how we described n8n Nod local browser sandboxes wrapping other harnesses.

Security checklist when you turn this on

Isolating bash tool execution so a compromised agent cannot reach production APIsIsolating bash tool execution so a compromised agent cannot reach production APIs

Google's README shifts these chores to you:

  1. Patch base images and rebuild on CVEs.
  2. Scope egress — allowlist domains; default-open internet is dangerous with browsing tools enabled.
  3. Rotate environment keys if a worker image leaks.
  4. Set idle timeouts so orphaned GPUs stop billing.
  5. Prove tenant isolation when multiple customers share a cluster.

For monitoring dangerous shell patterns, combine sandbox egress rules with harness policies like Claude cage VM network isolation patterns.

This is not a substitute for AgentBeam when your threat model is autonomous agents hitting production APIs — see our felony-bench tracker for why runtime isolation and policy gates stack.

Cost and performance expectations

Hosted preview environments still bill model tokens heavily — Google cites 100k–3M tokens per complex agent interaction in studio docs. Self-hosted mode adds your compute for workers without removing token charges.

Tradeoffs:

table · 2 cols
Hosted Google sandboxSelf-hosted worker
Fastest first runCold start depends on your autoscaler
Fixed Ubuntu 24.04 stackCustom CUDA, corporate apt mirrors
Google maintains imageYou patch glibc OpenSSL nightmares
Preview compute subsidyReserved instances or spot GPUs

Route cheap decision checks through Gemini Decision 1 before launching a full managed agent when the task is only routing.

How to try without production traffic

  1. Install CLI per Google install script.
  2. export GEMINI_API_KEY from AI Studio.
  3. Create a throwaway self_hosted environment; save environment_key.
  4. Run connect against a git clone in /workspace.
  5. Start an interaction from AI Studio or gemini-api agent run with that environment id.
  6. Compare latency and logs against default hosted mode on the same prompt.

Document token delta and wall time. If savings are negligible, hosted mode may still win for sporadic tasks.

Comparison with other managed agent stacks

table · 3 cols
ProductExecution choiceReference worker
Gemini managed agentsHosted or self-hostedgemini-api CLI
OpenAI Agents APIHosted + partners + BYOPartner sandboxes
Claude managed agentsAnthropic hosted + listed BYOConsole configuration
Amazon Bedrock AgentCoreAWS-managed runtimesAgentCore CLI 1.0

None of these eliminate prompt injection into tools. They redistribute blast radius.

When to pick self-hosted Gemini environments

Choose self-hosted when:

  • You already pay for E2B/Modal/Daytona capacity.
  • You need private package feeds inside the worker.
  • Legal asks for named subprocessors you control.

Stay on Google-hosted when:

  • You prototype in AI Studio only.
  • Tasks are short and network-light.
  • Your team lacks sandbox SRE time.

Interactions with Antigravity and Deep Research

Google markets Antigravity agent and Deep Research as managed agents on the same Interactions surface. Self-hosted environments should apply to any agent id that supports tool execution — verify in AI Studio before assuming Deep Research allows BYO sandboxes.

For IDE users, Chrome guidance for AI coding agents is orthogonal but shares the same security theme: untrusted code execution must stay bounded.

Migration path from hosted-only agents

Teams already shipping against hosted environments should not cut over in one step.

Week 1 — parity harness

Run the same golden tasks on hosted and on a connect worker in a disposable VPC. Capture tool latency, failure rates, and token counts. Hosted preview environments spin VMs down after idle; your worker must reproduce cold start behavior or you will mis-estimate SLA.

Week 2 — egress contract

Copy Google network allowlist semantics from AI Studio into your firewall. If agents call GitHub, PyPI, and your internal artifact host, list them explicitly. Silent full internet access is how LLMjacking mixers start.

Week 3 — key rotation

Practice rotating GEMINI_ENVIRONMENT_KEY without touching project API keys. Document which CI roles may create environments. Vault the one-time key material; Google will not resend it.

Week 4 — partner worker

Pick one launch partner manifest — Modal or E2B is usually fastest for Python agents — and deploy poll plus serve if you need keyless inner workers. Compare operator burden against Vercel KVM escape disclosures when arguing for microVM vendors.

Data residency checklist (honest version)

Self-hosted marketing often implies data never leaves your region. Google's architecture still requires:

  • Lease requests to Google APIs
  • Model weights running on Google infrastructure
  • Tool outputs returning upstream for the next reasoning step

What stays local:

  • Files on disk inside --root-dir
  • Stderr from commands unless your worker uploads it
  • Packages cached in your image layers

Legal review should ask what the worker serializes back, not only where bash runs. Pair with Gemini healthcare preview skills policy mindset if PHI might touch files.

Failure modes engineers report in similar systems

Even without Gemini-specific incident data, other agent sandboxes teach predictable breaks:

table · 2 cols
FailureMitigation
Worker loses lease mid-commandHeartbeat loops in connect; supervisor restarts
Drift between poller and executor versionsPin gemini-api CLI version in both images
Oversized stdout floods APITruncate and spill to object storage in worker
Malicious package supply chainInternal PyPI mirror, hash pinning
Prompt injection writes outside rootRead-only upper mounts, separate user namespaces

Runtime policy gates remain relevant when agents touch production databases, not only when sandboxes exist — see multi-agent engineering problems.

Observability hooks

Log these fields per interaction:

  1. environment_id and mode (self_hosted vs hosted)
  2. Worker region and image digest
  3. Tool name and duration
  4. Whether execution failed closed or retried

Correlate with Gemini billing exports to spot agents that loop on shell errors. Decision-model pre-checks from Hugging Face System One API can skip full agent spins for binary gates.

Enterprise procurement talking points

Security reviewers will ask how self-hosted differs from Anthropic computer use or OpenAI Codex cloud. Honest answers:

  • Google still operates the planning loop.
  • You operate kernel-adjacent execution.
  • Partner SLAs cover isolation, not model safety.

Link Factory OpenCompute self-hosted orchestrator only as analogy — different vendor, same buyer question.

Related reading

  • Files and Credentials APIs launch
  • Gemini Decision 1 routing API
  • OpenAI Agents API sandbox options
  • Agent sandbox vendor comparison
  • Capsem VM sandbox patterns for coding agents
  • Perplexity SPACE open Firecracker sandbox

CLI behavior accurate to google-gemini/gemini-api-cli main branch README and docs/self-hosted retrieved November 11, 2026.

Spotted something out of date? Let us know.
Daily briefFrom Yash · 350K+ students taught

Catch up on AI

One AI story explained in plain English, plus one thing to try. Every day, free. Unsubscribe anytime.

  • ✓ Free
  • ✓ One email a day, no spam
  • ✓ Unsubscribe anytime
Yash Thakker

Written by

Yash Thakker

Yash is an AI expert with over 300K learners. Join his workshops →

View Yash Thakker in People in AI →

Related posts

Oct 15, 2026

Capsem: An Open-Source VM Sandbox for Claude Code, Gemini CLI and Codex

Capsem is an Apache-2.0 Rust project that boots each AI coding agent session in a fresh, air-gapped Linux VM and forces all traffic through an inspecting proxy. explainx.ai reads the README and site, flags the contradictions, and shows how to evaluate it.

Sep 18, 2026

Gemini Managed Agents Get Files and Credentials APIs

Google updated its Gemini API managed agents with a new harness, antigravity-preview-09-2026, bringing the Antigravity coding agent's tools and behavior into AI Studio and the Interactions API on Gemini 3.8 Flash. Two new APIs ship alongside it: Files, for moving data in and out of an agent's sandbox, and Credentials, which lets an agent call GitHub or Slack without the model ever seeing the actual token.

Nov 8, 2026

Agent Sandboxes for Coding Agents Compared: Isolation, Cost, and Lock-In

Coding agents need a place to run untrusted shell commands. E2B, Modal, Daytona, Cloudflare Sandbox SDK, and Perplexity's open-source SPACE stack microVMs, containers, and edge runtimes differently. This guide maps isolation models, startup time, networking, and billing so you can match a sandbox to your threat model — not a marketing slider.