Skip to main content

Coding agents

Gemini CLI

Run Google's Gemini CLI in a sandbox from the prebuilt gemini template. Give it a Gemini API key and a task, and it works on the sandbox's files, terminal and git.

Maintained by
E2B
How it works
Prebuilt gemini sandbox template
Package
e2b
Language
TypeScript, Python

Set it up

Get started

Paste the prompt into your coding agent, or follow the steps yourself.

Paste this into your coding agent

Run Gemini CLI in an E2B sandbox from this project.

  1. 1.Install the e2b SDK using the project's package manager.
  2. 2.The SDK needs the E2B_API_KEY environment variable, and Gemini CLI needs GEMINI_API_KEY. If E2B_API_KEY isn't set, ask me for my API key from https://console.e2b.dev/?tab=keys. Never hardcode either key.
  3. 3.Follow the Gemini CLI guide at https://docs.e2b.dev/agents/gemini-cli: create a sandbox from the gemini template, pass GEMINI_API_KEY in envs, and run gemini --skip-trust --yolo -p with a command timeout of 0. Kill the sandbox when it's done.
  4. 4.Run one task and show me the output that came from the sandbox.

Or set it up yourself

  1. 1. Install the E2B SDK

    npm init -y && npm pkg set type=module
    npm install e2b
    npm install -D tsx
  2. 2. Set your API keys

    export E2B_API_KEY="e2b_..."
    export GEMINI_API_KEY="..."
  3. 3. Run Gemini CLI headless

    import { Sandbox } from 'e2b'
    
    const sandbox = await Sandbox.create('gemini', {
      envs: { GEMINI_API_KEY: process.env.GEMINI_API_KEY! },
      timeoutMs: 600_000,
    })
    
    const result = await sandbox.commands.run(
      `gemini --skip-trust --yolo -p "Create a hello world HTTP server in Python"`,
      { timeoutMs: 0 }
    )
    
    console.log(result.stdout)
    await sandbox.kill()
  4. 4. Work on a repository

    await sandbox.commands.run(
      'git clone --depth 1 https://x-access-token:$GITHUB_TOKEN@github.com/<owner>/<repo>.git /home/user/repo',
      { envs: { GITHUB_TOKEN: process.env.GITHUB_TOKEN! } }
    )
    
    await sandbox.commands.run(
      `cd /home/user/repo && gemini --skip-trust --yolo -p "Add error handling to all API endpoints"`,
      { timeoutMs: 0 }
    )
    
    const diff = await sandbox.commands.run('cd /home/user/repo && git diff')
    console.log(diff.stdout)

Security

What runs in the sandbox

Gemini CLI and every command it runs live in the sandbox, away from your machine.

  • Agentgemini with -⁠-⁠yolo auto-approving tool calls and -⁠-⁠skip-⁠trust trusting the working folder for the run.
  • FilesThe repo you clone and every change Gemini CLI makes. Read the result back with git diff.
  • SessionsSessions are saved per folder under ~/.gemini. -⁠-⁠resume latest continues the most recent one.
  • NetworkInternet access is on by default. Restrict outbound traffic with network rules for untrusted input or secrets.

3B+ sandboxes started

Give every agent a machine