Codex sandbox
This guide covers authentication, configuration, and usage of Codex in a sandboxed environment.
Official documentation: Codex CLI
Quick start
Create a sandbox and run Codex for a project directory:
$ docker sandbox run codex ~/my-project
The workspace parameter is optional and defaults to the current directory:
$ cd ~/my-project
$ docker sandbox run codex
Authentication
Codex requires an OpenAI API key. Credentials are scoped per sandbox.
Set the OPENAI_API_KEY environment variable in your shell configuration file.
Docker Sandboxes use a daemon process that doesn't inherit environment variables from your current shell session. To make your API key available to sandboxes, set it globally in your shell configuration file.
Add the API key to your shell configuration file:
export OPENAI_API_KEY=sk-xxxxxApply the changes:
- Source your shell configuration:
source ~/.bashrc(or~/.zshrc) - Restart Docker Desktop so the daemon picks up the new environment variable
- Create and run your sandbox:
$ docker sandbox create codex ~/project
$ docker sandbox run <sandbox-name>
The sandbox detects the environment variable and uses it automatically.
Configuration
Codex supports a YOLO mode that disables safety checks and approval prompts. This mode grants the agent full access to your sandbox environment without interactive confirmation.
Configure YOLO mode in ~/.codex/config.toml:
approval_policy = "never"
sandbox_mode = "danger-full-access"With these settings, Codex runs without approval prompts.
Pass options at runtime
Pass Codex CLI options after the sandbox name and a -- separator:
$ docker sandbox run <sandbox-name> -- --dangerously-bypass-approvals-and-sandbox
This flag enables YOLO mode for a single session without modifying the configuration file.
Base image
Template: docker/sandbox-templates:codex
Codex launches with --dangerously-bypass-approvals-and-sandbox by default when YOLO mode is configured.
See Custom templates to build your own agent images.