Share feedback
Answers are generated based on the documentation.

Codex sandbox

Availability: Experimental
Requires: Docker Desktop 4.58 or later

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:

~/.bashrc or ~/.zshrc
export OPENAI_API_KEY=sk-xxxxx

Apply the changes:

  1. Source your shell configuration: source ~/.bashrc (or ~/.zshrc)
  2. Restart Docker Desktop so the daemon picks up the new environment variable
  3. 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.