Skip to content
Overview

AI Agents

AI Agents are a set of pre-built coding agent runtime environments on the platform. They come with mainstream coding agent CLIs and their dependency toolchains pre-installed, enabling headless AI-driven code generation, modification, debugging, and git collaboration within isolated sandbox environments. Each runtime provides a complete file system, terminal, and git access, ready to use with compatible SDKs and key injection rules.

No API keys are built into the images. All authentication information is injected via envs when creating a sandbox, or rewritten by the platform on outbound links through key injection rules, preventing real keys from appearing in the sandbox process's environment variables.

Template List

Template NameBuilt-in CLIPrimary Authentication Environment VariablesDocumentation
claudeClaude Code CLI (Anthropic)ANTHROPIC_API_KEY (optional ANTHROPIC_BASE_URL)Claude Code
codexOpenAI Codex CLIOPENAI_API_KEYCodex
opencodeOpenCode CLI (multi-provider)ANTHROPIC_API_KEY / OPENAI_API_KEY / GEMINI_API_KEYOpenCode
ampSourcegraph Amp CLIAMP_API_KEYAmp

Common Features

All AI Agent templates share the following commonalities and are used in a highly consistent manner:

  • Pre-installed base tools: Node.js 24.x, git, ripgrep, vim, GitHub CLI, and frontend scaffolding tools like pnpm/tsx/vite. You can directly clone repositories, run scripts, and submit diffs.
  • Headless execution: Each CLI supports a non-interactive mode (-p / exec / run / -x), allowing you to trigger it once and get results via sandbox.commands.run().
  • Streaming event output: Use flags like --output-format stream-json / --json / --stream-json to output a JSONL event stream, enabling real-time monitoring of token usage, tool calls, and execution status.
  • Git repository integration: Use sandbox.git.clone() to pull a target repository directly into the sandbox, allowing the agent to make changes to real code and review them via git diff.
  • Key injection support: By creating injection rules of type anthropic / openai / gemini, real keys can remain on the platform side, while the CLI in the sandbox only holds placeholders.

General Usage Pattern

The typical invocation flow for all four templates is consistent, with differences mainly in the CLI command itself:

javascript
import { Sandbox } from 'e2b'

// 1. Create sandbox and inject authentication
const sandbox = await Sandbox.create('<template>', {
  envs: { /* API key for the corresponding template */ },
  timeoutMs: 600_000,
})

// 2. (Optional) Clone the target repository
await sandbox.git.clone('https://github.com/your-org/your-repo.git', {
  path: '/home/user/repo',
  username: 'x-access-token',
  password: process.env.GITHUB_TOKEN,
  depth: 1,
})

// 3. Drive the agent in headless mode
const result = await sandbox.commands.run(
  `cd /home/user/repo && <agent-cli> "<prompt>"`,
)

// 4. Review results and destroy the sandbox
console.log(result.stdout)
await sandbox.kill()

For details on specific CLI flags, streaming event formats, session/thread management, and custom system prompts, please refer to the respective sub-documents.