Skip to main content
Codex is OpenAI’s open-source coding agent. E2B provides a pre-built codex template with Codex already installed.

CLI

Create a sandbox with the E2B CLI.
Once inside the sandbox, start Codex.

Run headless

Use codex exec for non-interactive mode and --full-auto to auto-approve tool calls (safe inside E2B sandboxes). Pass --skip-git-repo-check to bypass git directory ownership checks inside the sandbox. Pass CODEX_API_KEY as an environment variable.

Example: work on a cloned repository

Use -C to set Codex’s working directory to a cloned repo.

Schema-validated output

Use --output-schema to constrain the agent’s final response to a JSON Schema. This ensures the output conforms to a specific structure — useful for building reliable pipelines.

Streaming events

Use --json to get a JSONL event stream. Each line is a JSON object representing an agent event (tool calls, file changes, messages). Progress goes to stderr; events go to stdout.

Image input

Pass screenshots or design mockups with --image to give Codex visual context alongside the prompt.

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 codex template.
Run the build script to create the template.

Sandbox persistence

Auto-pause, resume, and manage sandbox lifecycle

Git integration

Clone repos, manage branches, and push changes

SSH access

Connect to the sandbox via SSH for interactive sessions