OpenAI Codex
Run OpenAI's Codex CLI headless in a sandbox with its own filesystem, terminal and git. Point it at a repo, let it work, and collect the diff.
- E2B
- Prebuilt codex sandbox template
- e2b
- TypeScript, Python
Get started
Paste the prompt into your coding agent, or follow the steps yourself.
Paste this into your coding agent
Run OpenAI Codex in an E2B sandbox from this project.
- 1.Install the e2b SDK using the project's package manager.
- 2.The SDK needs the E2B_API_KEY environment variable, and Codex needs CODEX_API_KEY (an OpenAI 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.Follow the Codex guide at https://docs.e2b.dev/agents/codex: create a sandbox from the codex template, pass CODEX_API_KEY in envs, and run codex exec with --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check and a command timeout of 0. Kill the sandbox in a finally block.
- 4.Run one task and show me the output that came from the sandbox.
Or set it up yourself
1. Install the E2B SDK
2. Set your API keys
3. Run Codex headless
4. Work on a repository
What runs in the sandbox
Codex and every command it runs live in the sandbox, so its own command sandbox can stay off.
- codex exec with approvals and Codex's own sandbox bypassed. E2B is the isolation boundary instead.
- The repo you clone and every change Codex makes. Read results back with files.read() or git diff.
- Rollout files live under ~/.codex/sessions. codex exec resume continues a thread with a follow-up task.
- Internet access is on by default. Restrict outbound traffic with network rules for untrusted input or secrets.
More coding agents
Other coding agents that run in E2B sandboxes.
- Claude CodeRun Claude Code in its own sandbox with a real filesystem, terminal, and git, so it can work unattended.
- OpenCodeRun OpenCode in a sandbox, or keep it local and point its workspaces at E2B with the @e2b/opencode plugin.
- GitHub Copilot CLIRun GitHub Copilot CLI in a sandbox with full filesystem, terminal, and git access.
