Codex CLI Guide: Install, Sandbox, MCP and CI (2026)

By Updated

What is Codex CLI?

Codex CLI is OpenAI's coding agent that runs in the terminal inside your repository: it reads files, edits them and runs commands within a sandbox and an approval policy. You sign in with a ChatGPT plan or an API key, and scripts and CI use the non-interactive codex exec command.

TL;DR

  • -As of November 29, 2026 the latest stable release is 0.172.0 from November 24. The official install methods are a script, npm and Homebrew.
  • -ChatGPT sign-in draws on your plan's limit. An API key is billed at API prices and turns off cloud features. For CI, OpenAI's documentation recommends a key.
  • -There are three sandbox modes: read-only, workspace-write and danger-full-access. The -a flag accepts on-request and never; granular can be set only in the config. The untrusted value and the --full-auto flag are gone.
  • -In the author's test on 0.172.0, the agent in workspace-write fixed the code and ran the tests but couldn't run git commit: the .git directory is write-protected.
  • -In the same test, a short codex exec turn with one command used about 57,700 input tokens, 42,496 of them cached.

Codex CLI is OpenAI’s coding agent that runs in the terminal inside your repository: it reads files, edits them and runs commands within a sandbox and an approval policy. It installs with one command, signs in with a ChatGPT plan or an API key, and runs as codex exec in scripts and CI.

To start now:

curl -fsSL https://chatgpt.com/codex/install.sh | sh   # macOS and Linux
codex login                                            # sign in via browser
cd my-repo && codex                                    # interactive mode

In a folder under git, Codex offers the Auto preset: edits inside the project without asking, network off, approval for anything beyond.

Versions, prices and limits are as of November 29, 2026, from OpenAI’s documentation. “Author’s test” means the command ran on codex-cli 0.172.0 (macOS, ChatGPT sign-in, codex exec --ephemeral --ignore-user-config --json, model gpt-6.2-sol), one run per scenario. The MCP test used a separate clean CODEX_HOME the same day. A from-scratch install, Windows and Linux weren’t tested; those parts follow the documentation.

When you need the CLI

Codex comes as a CLI, a desktop app, an IDE extension and a cloud service. Pick the CLI if you live in the terminal, work on a remote machine or call the agent from scripts. The Claude Code vs Codex comparison covers models, cloud and prices. For an agent that isn’t tied to one vendor, see OpenCode.

Installing and updating Codex CLI

The latest stable release is 0.172.0 from November 24, 2026, also latest on npm. The official methods:

SystemInstallUpdate
macOS, Linuxcurl -fsSL https://chatgpt.com/codex/install.sh | shsame command
Windows (PowerShell)powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"same command
npmnpm install -g @openai/codexsame command
Homebrewbrew install --cask codexbrew upgrade --cask codex

After installing, run codex --version. codex update updates the CLI if the build supports it, and codex doctor reports on installation, config, auth and git.

On Linux and WSL2 the documentation says to install bubblewrap first: the sandbox depends on it. WSL1 isn’t supported since 0.115. For the neighboring tool, see how to install Claude Code.

Signing in: ChatGPT plan or API key

Your sign-in method decides cost and some features. A summary of the Authentication and Pricing pages:

ChatGPT planAPI key
How to sign incodex loginprintenv OPENAI_API_KEY | codex login --with-api-key
Billingplan limit, then creditsAPI prices
Modelsby planby key access
Codex cloud, GitHub PR review, Slackyes, on paid plansno
CItrusted runners only, no public repositoriesthe default option

codex login status shows the current method, codex logout resets it. Without a browser, use codex login --device-auth: it’s in beta, and you first enable device code sign-in in ChatGPT security settings. The fallback is ssh -L 1455:localhost:1455 user@remote to forward the callback port, with codex login in that session.

Tokens live in ~/.codex/auth.json as plain text or in the OS credential store. Don’t commit or share that file. For Keychain or its equivalent, set cli_auth_credentials_store = "keyring" in the config.

First run and useful commands

Run codex in the repository root and start with a question, no edits. The commands you’ll use most:

  • /status shows the model, approval policy, writable directories and remaining context.
  • /permissions changes permissions on the fly, e.g. Auto to read-only.
  • /model switches model and reasoning effort.
  • /init creates a starter AGENTS.md.
  • /diff shows changes, /review asks the agent to check them.
  • /compact compresses history after a long session.

codex resume continues a closed session. Commit before a task so edits are easy to roll back.

Models and reasoning effort

GPT-6.2 Astra and Sol came out on November 17, 2026. With no model set, Codex picks the recommended one; in the author’s test that was gpt-6.2-sol.

ModelFor what (per the documentation)Default contextMessages per 5 hours on Plus, estimateCredits per 1M: input / cached / output
gpt-6.2-astrathe hardest tasks272,0006-50200 / 10 / 1,000
gpt-6.2-soleveryday code500,00017-18050 / 2.5 / 250
gpt-6.1-sollong repetitive tasks500,00015-16050 / 2.5 / 250
gpt-6.1-terratext, images, computer use; needs CLI 0.159.0+not stated35-28525 / 1.25 / 125
gpt-6-lunasimple tasks in bulknot stated350-3,0002.5 / 0.25 / 12.5

Both GPT-6.2 models support a window of up to 1M tokens, set with model_context_window. In Enterprise and Edu they’re off until an administrator enables them.

Change the model with -m gpt-6.2-sol, /model or the model config key. model_reasoning_effort sets reasoning depth: low, medium, high, xhigh, max, ultra, depending on the model. ultra brings in subagents; Luna doesn’t have it. The documentation suggests the client’s choice for GPT-6.2 and high for Luna.

Old model names break scripts. With ChatGPT sign-in, gpt-5.4 was retired on August 31 and gpt-5.5 on October 14, 2026. API key sessions weren’t affected.

Codex sandbox: what the agent can physically do

The sandbox limits commands at the OS level (Seatbelt on macOS, bwrap and seccomp on Linux), and the approval policy decides when the agent must ask. Combinations from the documentation:

ScenarioFlagsWhat happens
Autonone, or --sandbox workspace-write --ask-for-approval on-requestedits the project itself, asks before leaving it or using the network
Review--sandbox read-only --ask-for-approval on-requestreads and runs commands without writing
CI without edits--sandbox read-only --ask-for-approval neversame, but never asks
Automatic review--approve-for-meworkspace-write; a reviewer agent checks requests, model usage is higher
Full access--dangerously-bypass-approvals-and-sandbox (--yolo)no sandbox, no questions; isolated environments only

Codex recommends Auto in a version-controlled folder and read-only elsewhere. The reference doesn’t state the exact approval_policy default, so check /status.

What the test showed

Test repository: calc.py, three tests with one failing, and AGENTS.md. Author’s test, one run per scenario.

ActionResult
”Fix the test”, -s read-onlyedit rejected: writing is blocked by read-only sandbox; the model checked the fix in memory and showed the code
”Fix the test”, -s workspace-writefixed, 3 tests passed, 21 s
curl in workspace-writeexit 6, Could not resolve host
same with -c sandbox_workspace_write.network_access=trueHTTP 200
write to the home folder, outside the projectOperation not permitted
git commit in workspace-write.git/index.lock: Operation not permitted, exit 128
codex sandbox -- sh -c …writing to /tmp and network denied by default

The last row is codex sandbox, a separate command that runs anything under Codex’s policy without a model (the reference shows macos, linux and windows subcommands; the -- form worked in the test). In workspace-write, the documentation includes /tmp in the workspace.

Why the agent couldn’t commit

The git commit failure matches the documentation. Inside writable directories .git, .agents, .codex and .aws are recursively read-only, and Advanced Config says this is why git commit “may still require approval to run outside the sandbox”. Git failed at its first step, index.lock.

Interactive mode with on-request may ask you. In the codex exec test the policy was never, so the command failed. The workable setup: the agent edits files, you or the next pipeline step commit. Per the documentation, a prefix_rule with decision = "allow" can permit git commit (rules are marked experimental), but then it runs outside the sandbox with the repository’s git hooks. If the agent may edit those hooks, the boundary is gone. Not tested.

Approvals: flag and config accept different values

WhereValues accepted in 0.172.0
-a / --ask-for-approval flagon-request, never (author’s test; same in the tag’s source)
approval_policy key in config.tomlon-request, never and a granular object (per the reference, not tested)

granular keeps prompts for the categories you choose and rejects the rest automatically:

approval_policy = { granular = { sandbox_approval = true, rules = true, mcp_elicitations = true, request_permissions = false, skill_approval = false } }

on-failure is deprecated; untrusted is no longer supported and may keep the client from starting. If you used untrusted to confirm every command, the documentation suggests dropping the explicit approval_policy and marking the project in ~/.codex/config.toml:

[projects."/path/to/project"]
trust_level = "untrusted"

network_access = true opens the whole network to commands. Domain rules work only with [features.network_proxy] enabled, and the proxy doesn’t filter web search, MCP connections or the model’s own requests. Web search defaults to cached (OpenAI’s index), --search switches it to live, web_search = "disabled" turns it off.

config.toml: layers, profiles, overrides

The precedence order, strongest first:

  1. CLI flags and -c key=value.
  2. Project .codex/config.toml files, nearest to the current directory wins; trusted projects only.
  3. The --profile <name> file.
  4. ~/.codex/config.toml.
  5. Cloud workspace settings, /etc/codex/config.toml, built-in values.

A profile is weaker than project config: sandbox and approval keys aren’t on the list Codex ignores in a project .codex/config.toml, so a trusted repository can loosen a strict personal profile. Pass hard limits as flags.

Since 0.134.0 a profile is a separate ~/.codex/<name>.config.toml file with top-level keys. Codex no longer reads the [profiles.<name>] table or the profile = "…" key. An untested example from the documentation:

# ~/.codex/careful.config.toml, run: codex --profile careful
sandbox_mode = "read-only"
approval_policy = "on-request"
web_search = "disabled"

[shell_environment_policy]
ignore_default_excludes = false

The last line drops variables with KEY, SECRET or TOKEN in the name from command environments. The default is true, which leaves that filter off.

--strict-config catches a mistyped key. In the author’s test: unknown configuration field `approvl_policy` in -c/--config override.

AGENTS.md

Codex reads the global ~/.codex/AGENTS.md, then one file per directory from the project root to the current one, and concatenates them, nearest last. The total limit is 32 KiB.

In the author’s test (one run each) the root AGENTS.md worked. An AGENTS.override.md next to it replaced it, and a file in a subfolder beat the root one when launched from there. With project_doc_max_bytes=10 the file was cut off, the instruction wasn’t followed, and the last lines of output had no warning. If a rule stops working, check file sizes. For writing one for several agents, see the AGENTS.md guide.

MCP, skills and subagents

codex mcp add <name> -- <command> adds a stdio MCP server, --url <URL> an HTTP one; both write an [mcp_servers.<name>] table. In the author’s test codex mcp list showed enabled even with the HTTP server down, because it doesn’t check the connection. And codex exec without extra settings rejected the tool call: MCP tool call requires approval, but approval policy is never. With this config the call went through:

[mcp_servers.rates]
command = "python"
args = ["server.py"]
default_tools_approval_mode = "approve"

Set approve only for servers you trust, and narrow tools with enabled_tools. Do you need MCP at all? See MCP vs API.

Skills are folders with SKILL.md in the repository’s .agents/skills or in $HOME/.agents/skills; /skills lists them. Subagents are on by default, start on request or by instruction, and use more tokens than a single agent.

codex exec in CI

codex exec runs a task without an interface: progress goes to stderr, the final answer to stdout. The default sandbox is read-only; edits need an explicit mode.

# check without edits, answer matching a JSON Schema
codex exec --ephemeral --output-schema ./schema.json -o result.json \
  "Find exception handling errors in the diff"

# edits inside the project, events as JSONL
codex exec --sandbox workspace-write --json "Fix the failing test" > events.jsonl

# continue the last session (it must not be --ephemeral)
codex exec resume --last "Add a test for the edge case"

Keep in mind:

  • Outside git, codex exec refuses to run. In the author’s test: Not inside a trusted directory and --skip-git-repo-check was not specified.
  • In the author’s test --output-schema returned JSON matching the schema, but an AGENTS.md instruction to add a word at the end landed inside a string field. Keep answer-format rules out of such repositories.
  • Project config and MCP from the repository load only if the project is trusted; --trust saves that.
  • Pass the key per call through CODEX_API_KEY. Don’t set it job-wide: repository code can read the environment.

For GitHub Actions there’s the official openai/codex-action@v1. Based on the documentation example:

jobs:
  codex:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    outputs:
      final_message: ${{ steps.run_codex.outputs.final-message }}
    steps:
      - uses: actions/checkout@v5
        with:
          persist-credentials: false
      - id: run_codex
        uses: openai/codex-action@v1
        with:
          openai-api-key: ${{ secrets.OPENAI_API_KEY }}
          prompt-file: .github/codex/prompts/review.md
          sandbox: read-only

A second job with write permissions but no key posts the comment or pull request. If the agent edits code, OpenAI’s example saves git diff as an artifact for another job to apply and commit. Treat prompts from outside PRs as untrusted input.

Limits and cost

OptionPrice on November 29, 2026About the CLI
Free, Go$0, $8 a monththe card lists only GPT-6 Luna in the desktop app
Plus$20 a monthCLI listed; 5-hour limit
Pro$100, $200 or $500 a monthcurrently no 5-hour limit
Business$20 per seat billed annually, $25 monthly, 2 seats minimumStandard message estimates same as Plus
Enterprise, Eduby contractcredit usage or per-seat limits
API keyAPI pricesno cloud features

Local and cloud tasks share one limit; weekly limits may apply. /status shows what’s left.

What one turn cost in the author’s test on gpt-6.2-sol, with credits calculated from the model table:

TurnInput tokensCachedOutputCredits, calculated
short, one command≈57,70042,496not recorded≈0.9 without output
fixing a test, workspace-write146,560130,176370≈1.2
same in read-only170,493154,624744≈1.4

Even a short turn is two model calls of about 29K base tokens each. The read-only attempt cost more than the successful edit. Three runs on a tiny project don’t extrapolate to a large repository. To spend less, the documentation suggests a short AGENTS.md, fewer MCP servers, narrow tasks and a smaller model.

Common Codex CLI errors

SymptomCauseWhat to doStatus
--full-auto: unexpected argumentflag removed--sandbox workspace-write or --approve-for-metest
codex exec doesn’t change filesread-only by default--sandbox workspace-writetest and docs
Could not resolve hostno network in workspace-writenetwork_access = truetest
index.lock: Operation not permitted.git is protectedcommit outside the sandboxtest
MCP tool rejected in execnever policydefault_tools_approval_mode = "approve"test
client won’t start after an updateapproval_policy = "untrusted"on-requestdocs
--profile x has no effectold [profiles.x]a ~/.codex/x.config.toml filedocs
script with gpt-5.5 failsmodel retired for ChatGPT sign-ina model on your plandocs
custom provider doesn’t workneeds the Responses APIwire_api = "chat" isn’t supporteddocs

What this guide doesn’t cover

Not tested: the exact approval_policy default, behavior on Windows and Linux, granular, permission profiles (beta), hooks and Codex cloud. Recent versions dropped --full-auto, untrusted and old profiles. Before moving commands to CI, pin the CLI version (the action has a codex-version parameter) and check codex --help.

Checklist before team use

  1. Pin the CLI version and the model in CI.
  2. Use Auto for people, read-only for checks, workspace-write in a separate job for automated edits.
  3. Decide who commits: in workspace-write, .git is write-protected.
  4. Keep the network off, open it by domain through network_proxy.
  5. Set ignore_default_excludes = false so secrets don’t reach commands.
  6. Check the total size of AGENTS.md and the list of MCP servers.
  7. Search your scripts for --full-auto, untrusted, [profiles. and gpt-5..

Start with 7: grep -rnE -e '--full-auto|untrusted|\[profiles\.|gpt-5\.' .github scripts shows what an update will break.

Frequently Asked Questions

Is Codex CLI free?
As of November 29, 2026 OpenAI's documentation doesn't promise free access to the CLI. The Free and Go cards name only GPT-6 Luna in the desktop app, and the CLI is listed explicitly starting with Plus at $20 a month. The alternative is an API key billed at API prices.
Do I need an API key, or is a ChatGPT subscription enough?
On your own machine, ChatGPT sign-in on a paid plan is enough: usage counts against the plan limit. An API key is handier in CI and scripts, and the documentation calls keys the right default for automation. With a key you lose Codex cloud, GitHub pull request review and the Slack integration.
What's the difference between read-only, workspace-write and danger-full-access?
In read-only the agent reads files and runs commands without write access. In workspace-write it edits files in the working directory, commands have no network, and .git, .agents, .codex and .aws inside it stay read-only. danger-full-access removes the sandbox limits and is meant for an isolated container or runner.
Can Codex run git commit itself?
Not in the author's workspace-write sandbox: in a test on codex-cli 0.172.0 (one run) the command failed with .git/index.lock: Operation not permitted and exit code 128. Per the documentation .git is write-protected, so git commit may require approval to run outside the sandbox. In codex exec with the never policy nobody can approve, so you or the next CI step make the commit.
How do I run Codex in GitHub Actions?
The documentation recommends openai/codex-action@v1: the action installs the CLI and starts a proxy to the Responses API so the key is less exposed in the environment. The Codex job gets contents: read, and a separate job without the key posts comments and pull requests. Don't set the key as a variable for a whole job that runs repository code.
Where do instructions for Codex go?
In AGENTS.md at the repository root, with personal rules in ~/.codex/AGENTS.md. Codex concatenates files from the root down to the current directory and stops when the total reaches project_doc_max_bytes, 32 KiB by default. An AGENTS.override.md file replaces AGENTS.md in the same directory.
Codex CLI or Claude Code?
Both run in the terminal and in CI. They differ in models, sandbox design and plans. If you already pay for ChatGPT, start with Codex CLI; if you pay for Claude, start with Claude Code. The blog has a detailed comparison.