Enterprise engineering teams rarely want managed cloud agents executing shell commands inside Google-hosted sandboxes when source code, private registries, or air-gapped datasets sit inside their own VPC. With gemini-api-cli v0.5.0, Google ships the self-hosted BYOS (Bring Your Own Sandbox) runtime directly inside the gemini-api binary.
When a client creates an environment with {"mode": "self_hosted"} on POST /v1beta/environments, the API returns a unique environment ID alongside a one-time scoped environment_key. Workers inside your infrastructure poll POST /v1beta/environments:leaseInteractions over standard outbound HTTPS—requiring zero inbound firewall ports—and execute Gemini built-in tools (execute_bash, read_file, write_file, edit_file, list_dir, grep_search, find_by_name) strictly confined to --root-dir and --workdir.
gemini-api environments connect): Ideal for Cloud Run jobs, Docker containers, Modal, E2B, Daytona, Vercel Sandbox, Fly.io Sprites/Machines, and Cloudflare Sandboxes. The container holds only GEMINI_ENVIRONMENT_KEY (never your project-wide GEMINI_API_KEY).environments poll + environments serve): Designed for Agent Substrate Kubernetes clusters (ate.dev/v1 WorkerPool) and hardened ephemeral sandboxes. A trusted control-plane poller holds the environment key, maintains background handoff heartbeats while compute boots, and invokes --provision-cmd with a v1 JSON payload on stdin containing interaction_id, lease_token (prefixed lt_v1_), and environment_config.custom_config. The untrusted container holds zero API keys and attaches using only the short-lived interaction-scoped --lease-token.# Trusted control plane: poll for leased interactions and spawn isolated sandboxes
gemini-api environments poll \
--environment-key "$GEMINI_ENVIRONMENT_KEY" \
--provision-cmd ./scripts/spawn-ephemeral-pod.sh
# Inside the untrusted ephemeral sandbox (holds ZERO API keys, only lt_v1_ lease token):
gemini-api environments serve \
--interaction-id "$INTERACTION_ID" \
--lease-token "$LEASE_TOKEN" \
--root-dir /workspace \
--workdir /workspace
Security Boundary Note: Google's docs/self-hosted/local/ documentation explicitly warns against running environments connect directly on a developer's host workstation because execute_bash inherits the host user's permissions. Production deployments should always isolate workers inside rootless Docker/Podman containers, microVMs, Agent Substrate Pods, or Cloudflare Sandboxes.