# Codex in Docker

> Run Codex in a container: EnvHaven's open-source image with Codex built in, a managed workspace with nothing to run, and the folders and keys a container of your own has to keep.

_Updated November 23, 2026 · Checked against Codex 0.157.1 in EnvHaven v1.9.0_

A container keeps whatever Codex does with full access away from your own files, which makes it the usual home for unattended runs. EnvHaven is built on that idea in two forms: a managed workspace, which is the container already running on a server of its own, and the open-source workspace image, which you run with Docker yourself.

## A managed workspace: nothing to run

1. Open your workspace in any browser. It is the EnvHaven container on its own always-on server, with an HTTPS address for what you build.
2. Tap **Launch**, choose Codex and tap **Sign in**: it runs `codex login --device-auth`, which shows a one-time code to approve in ChatGPT (turn on device code sign-in in ChatGPT's security settings first).
3. Start it with one tap: signed in, Codex gets a green dot in the Launch menu and an icon in the workspace's top bar. Support is built in (0.157.1), so there is nothing to install or update.
4. Give it a task. The image writes both settings into `~/.codex/config.toml`, so `codex` starts without approvals.

## The EnvHaven image, on your own Docker

The workspace image is MIT-licensed and ships Codex 0.157.1 beside 16 other agents. Its home is `/config`, so one volume keeps every agent's settings and sign-in when the container is replaced:

```bash
docker run -d \
  --name envhaven \
  -p 8443:8443 \
  -p 2222:22 \
  -e PASSWORD=password \
  -e SUDO_PASSWORD=password \
  -v envhaven-config:/config \
  ghcr.io/envhaven/envhaven:latest
```

Open `http://localhost:8443`, run `codex` in the terminal and sign in. The [self-hosted guide](https://envhaven.com/guides/self-hosted-dev-environment) covers SSH and Haven CLI against it.

## What a container for Codex has to keep

Codex keeps its settings in `~/.codex` ([source](https://learn.chatgpt.com/docs/auth)). `CODEX_HOME` (default `~/.codex`) holds `config.toml`, history, sessions and, when the sign-in is cached as a file, `auth.json`.

In a container of your own, mount a volume there so a rebuilt container stays signed in. Codex also reads `CODEX_API_KEY` instead of a sign-in in non-interactive runs such as `codex exec` ([source](https://developers.openai.com/codex/noninteractive)).

## Full access inside the container

For one session:

```bash
codex --dangerously-bypass-approvals-and-sandbox
```

As the default, in ~/.codex/config.toml:

```toml
approval_policy = "never"
sandbox_mode = "danger-full-access"
```

The flag turns off approvals and the sandbox together; its help calls it "EXTREMELY DANGEROUS" and meant for environments that are already sandboxed, and OpenAI's docs recommend full access inside Docker for that reason. Quote the values in config.toml: an unquoted `never` fails with "Error loading config.toml". Administrators can forbid both values through requirements.toml.

## Keep reading

- [Codex](https://envhaven.com/agents/codex)
- [Codex in the browser](https://envhaven.com/agents/codex/browser)
- [Codex on iPhone](https://envhaven.com/agents/codex/iphone)
- [Codex on iPad](https://envhaven.com/agents/codex/ipad)
- [Codex on Android](https://envhaven.com/agents/codex/android)
- [Codex on a Chromebook](https://envhaven.com/agents/codex/chromebook)
- [Coding agents in Docker](https://envhaven.com/agents/docker)

Source: https://envhaven.com/agents/codex/docker
