Run the Codex CLI in a sandbox with an OpenAI API key, a ChatGPT plan, or the open models of Munito AI.
Sign in
Use one of these three methods.
With an OpenAI API key
Put the key in the env of the sandbox:
{
"CODEX_API_KEY": "sk-..."
}codex execreadsCODEX_API_KEYfor each run.- For the terminal UI, sign in with the key one time:
printenv CODEX_API_KEY | codex login --with-api-key. - OpenAI recommends an API key for automation. See authentication.
With a ChatGPT plan
Sign in over SSH. Use a device code or your browser.
With a device code:
- Turn on device code sign-in in the security settings of ChatGPT, or of your workspace.
- Run
codex login --device-auth. - Open the link on a device, and type the code.
With your browser:
- Connect with
ssh -L 1455:localhost:1455. - Run
codex login. - Open the link in the browser of your computer. The forward sends the sign-in to the sandbox.
- Codex keeps the sign-in in
~/.codex/auth.json. Each latercodex execuses it. - Codex uses the usage limits of your plan.
With the open models of Munito AI
- Put your Munito AI key in the
envof the sandbox asMUNITO_API_KEY. - Write this configuration to
~/.codex/config.toml, with the files API or a command:
model = "zai-org/glm-5.3-flash"
model_provider = "munito"
[model_providers.munito]
name = "Munito"
base_url = "https://api.munito.ai/inference/v1"
env_key = "MUNITO_API_KEY"
wire_api = "responses"Codex with open models explains the provider, the model metadata and the regional hosts.
Run a task
curl -sS --fail-with-body "https://api.munito.ai/sandboxes/v1/sandboxes/$SANDBOX/exec" \
-H "Authorization: Bearer $MUNITO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"command": "cd /workspace && codex exec --skip-git-repo-check --dangerously-bypass-approvals-and-sandbox \"Write a Python script that prints the first 10 primes, and run it\"", "timeout": 1800}'codex execruns one task, and then it stops. It writes the progress to standard error, and the last message to standard output.--dangerously-bypass-approvals-and-sandboxlets Codex run commands and change files with no question. The sandbox of Munito AI isolates Codex, so Codex does not need its own sandbox.- Without this flag,
codex execcan only read files. --skip-git-repo-checklets Codex work in a folder that is not a Git repository. In a cloned repository, remove it.--jsongives each event of Codex as one line of JSON. With"stream": truein the request, the events come during the task.- For a task of more than 30 minutes, start
codex execin the background withnohup, and read its log with later commands.
Use the terminal UI
- Add your public key with SSH.
- Connect with the command that
GET /sandboxes/{sandbox_id}/sshgives. - Run
codexin/workspace.
To keep the session after you disconnect, install tmux (apt-get install -y tmux), and start Codex in it.