Skip to main content
Gemini CLI is Google’s open-source coding agent for the terminal. E2B provides a pre-built gemini template with Gemini CLI already installed.
Since June 18, 2026, Gemini CLI no longer serves free-tier and Google AI Pro and Ultra users who sign in with a Google account; it remains available with paid Gemini API keys, Vertex AI, and enterprise accounts (announcement). If you sign in with a Google account, use Antigravity CLI instead.

Authentication

Gemini CLI authenticates with the GEMINI_API_KEY environment variable. Create a key in Google AI Studio and pass it to the sandbox. Without credentials, headless runs exit immediately with an error instead of waiting for a sign-in; GOOGLE_API_KEY alone is not enough. To use Vertex AI, set GOOGLE_GENAI_USE_VERTEXAI=true, GOOGLE_CLOUD_PROJECT, GOOGLE_CLOUD_LOCATION, and either GOOGLE_API_KEY or GOOGLE_APPLICATION_CREDENTIALS instead; a service account key file has to be uploaded to the sandbox first. See the Gemini CLI authentication guide for details.

CLI

Create a sandbox with the E2B CLI and pass your API key to the terminal session.
Once inside the sandbox, start Gemini CLI. On the first start in a folder, it asks whether to trust that folder.

Run headless

Use -p for non-interactive mode, --yolo to auto-approve all tool calls, and --skip-trust to trust the working directory for the run. A fresh sandbox has no trusted folders, so without --skip-trust a headless run exits with an error and --yolo is ignored. Without --yolo, headless runs get no tools that edit files or run commands: the agent only reports that it cannot do the task, and the run still exits with code 0. Agent runs often take longer than the default command timeout, so pass timeoutMs: 0 (timeout=0 in Python) to wait until the run completes, and give the sandbox enough lifetime. When the API returns rate-limit errors, Gemini CLI retries with backoff, which can add minutes to a run.
Trusting a folder lets Gemini CLI load its project configuration: .gemini/settings.json, .env files, MCP servers, hooks, and custom commands. Pass --skip-trust only for code you are willing to run with the sandbox’s credentials.Auto-approving tool calls is contained by the sandbox: the agent cannot touch your host machine, local files, or credentials. It can still make outbound network requests — internet access is enabled by default. To limit where an auto-approved agent can connect, configure outbound network rules (allowInternetAccess, plus allow/deny lists by CIDR or hostname). Hostname rules apply to HTTP(S) traffic only; use CIDR rules for other protocols.
By default, Gemini CLI routes each request to a model automatically. To pin a model, pass -m (--model) or set the GEMINI_MODEL environment variable, for example to a Flash model for faster and cheaper runs. See the Gemini API models for the models available to your key.

Example: work on a cloned repository

Streaming events

Use --output-format stream-json to get a real-time JSONL event stream: an init event with the session ID and model, message events for the prompt and response text, tool_use and tool_result events for tool calls, and a final result event with the status and token usage.

Resume a session

Gemini CLI saves sessions per project directory under ~/.gemini in the sandbox. Run follow-up tasks from the same directory with --resume latest, or list sessions with --list-sessions and pass an index to --resume.

Build a custom template

If you need to customize the environment (e.g. pre-install dependencies, add config files), build your own template on top of the pre-built gemini template.
Run the build script to create the template.

Cookbook example

Gemini CLI fixing a failing test in a sandbox, in TypeScript and Python

Sandbox persistence

Auto-pause, resume, and manage sandbox lifecycle

SSH access

Connect to the sandbox via SSH for interactive sessions