---
title: "Codex"
description: "Run Codex in a box with an OpenAI API key, a host-managed ChatGPT login or a device login inside the guest."
---

> Documentation Index
> Fetch the complete documentation index at: https://sandrinodm.github.io/agent-box/llms.txt
> Use this file to discover all available pages before exploring further.

# Codex

Codex is OpenAI's coding agent CLI. abx installs `@openai/codex` 0.173.0 from npm into the image. Use this page to choose between an API key, a ChatGPT login managed on the host, and a device login stored in the box.

## Launch

```sh
abx codex <box>
```

abx runs `codex --dangerously-bypass-approvals-and-sandbox` in the guest. Arguments after `--` go to Codex:

```sh
abx codex version-check --net off -- --version
```

## Authentication

| Mode | Access | What it does |
| --- | --- | --- |
| `openai/api-key` | masked | A host-managed OpenAI API key. The guest gets a handle bound to `api.openai.com`. |
| `openai/device` | masked | Host-managed ChatGPT login. The host signs in and renews it, and the guest gets a handle for `chatgpt.com`. |
| `openai/device` | global, local | `codex login --device-auth` runs in the box, and Codex stores and renews the ChatGPT login there. |
| `openai/login` | none | Not available in a box. |

`openai/device` appears twice, once for the host-managed route and once for the guest login. When you select it with `abx auth set` and no `--profile`, add `--access` to say which one. Without it the command fails and asks for `--access masked|global|local`.

### API key (masked)

```sh
abx auth set codex --provider openai --mode api-key --from 'op://Development/OpenAI/api-key'
abx auth verify codex
abx codex first-task
```

See [Secret providers](https://sandrinodm.github.io/agent-box/authentication/secret-providers/).

### ChatGPT login on the host (masked)

Install the Codex CLI on the host at exactly version 0.173.0, the version abx pins. abx compares the two exactly. Then sign in under a profile name:

```sh
abx auth login codex --provider openai --mode device --profile work
abx auth verify codex
abx codex first-task
abx codex second-task
```

`abx auth login` always uses masked access. The login belongs to Codex and is not shared with Pi or OpenCode. The Linux client layout, trust rules and renewal after logout are in [Host-managed login](https://sandrinodm.github.io/agent-box/authentication/host-managed-login/).

### Device login in the guest (global or local)

For a login shared across boxes, start the device flow in a new box and finish consent in your browser. Exit Codex and stop the box before handing the profile to another box; `abx stop` refuses with `box-busy` while Codex is still running.

```sh
abx auth set codex --provider openai --mode device --access global
abx codex first --auth-profile personal -- login --device-auth
abx codex first
abx stop first
abx codex second --auth-profile personal
```

While the saved selection is `global`, creating a Codex box without `--auth-profile NAME` (or `--access local`) fails with `Global access requires --auth-profile NAME when creating a box.`

For a login that stays on one box:

```sh
abx codex solo --access local -- login --device-auth
abx codex solo
```

`--access local` at launch works when no Codex mode is saved, or when the saved mode is `openai/device`. If you saved an API key, save the guest route first with `abx auth set codex --provider openai --mode device --access local`.

Codex stores the login in `~/.codex/auth.json` in the guest. The account or workspace may need device authentication enabled in OpenAI's settings.

## Verification

`abx auth verify codex` applies to the two masked modes. Guest logins need no verification. `abx auth status codex` lists both `openai/device` routes; the access column tells them apart. See [Verification](https://sandrinodm.github.io/agent-box/authentication/verification/).

## Notes

- Codex's session transcripts (`.codex/sessions`) are kept on the host with the box.
- The box's hosts depend on the mode. With no saved login, and with an API key, the box may reach `api.openai.com`. With the host-managed ChatGPT login it may reach `chatgpt.com` only. With a device login in the guest it may reach `chatgpt.com` and `auth.openai.com`. Add other hosts with `--allow`. See [Network policy](https://sandrinodm.github.io/agent-box/network/policy/).

Source: https://sandrinodm.github.io/agent-box/agents/codex/index.mdx
