Codex CLI
OpenAI's open-source terminal coding agent with sandboxed execution and two-layer approval controls.
Codex CLI is OpenAI's open-source (Apache-2.0) coding agent that runs entirely in your terminal: it reads files, edits them on disk, and runs shell commands inside an OS-level sandbox that defaults to no network and workspace-scoped writes. Sandbox modes and approval policies control what it can do and when it must ask; auth is a ChatGPT plan or API key.
Codex CLI is OpenAI's open-source coding agent that runs entirely in your terminal. You point it at a repository, describe a task in plain language, and it reads files, edits them on disk, and runs shell commands to get the job done — all inside an OS-level sandbox that defaults to no network access and write permissions scoped to your workspace. It is written in Rust and ships as a binary installable via npm, Homebrew, or a one-line shell installer.
It is aimed at developers who live in the terminal and want an agent backed by OpenAI's frontier models without leaving the shell. You can authenticate with a ChatGPT plan (Plus, Pro, Business, Edu, or Enterprise) or an OPENAI_API_KEY, and the same binary works on macOS, Linux, and Windows (natively or via WSL).
Highlights
- Two-layer security model — sandbox modes (
read-only,workspace-write,danger-full-access, via--sandbox) control what the agent can technically do; approval policies (on-request,untrusted,never) control when it must stop and ask before acting. - Sandboxed by default — the
workspace-writemode limits writes to the active workspace and blocks outbound network, so edits stay local until you explicitly widen the boundary. - Model switching — use
/modelto move between GPT-5.5, GPT-5.4, GPT-5.4-mini, and other available models, and adjust reasoning effort per task. - MCP support — connect external tools by configuring Model Context Protocol servers (STDIO or streaming HTTP) in the config file.
- Non-interactive
codex exec— run Codex headlessly in scripts and CI, piping the final result to stdout. - Session resume and image input — pick up past transcripts with
codex resume, and attach screenshots or design specs as context.
In an AI-assisted workflow
Codex CLI fits where you already run Git and your build. A typical loop is to start it in a repo with the default workspace-write sandbox mode and on-request approval policy, let it draft edits, and approve anything that reaches outside the workspace or touches the network. It reads AGENTS.md files for project-specific context, so you can encode conventions and commands once and have them apply on every run.
npm install -g @openai/codex
cd your-project
codex "Add a retry with backoff to the API client and a test for it"TIP
Start with the read-only sandbox mode on an unfamiliar repository to have Codex propose a plan before it edits anything, then widen to workspace-write once you trust the direction.
NOTE
Unlike Aider, Codex does not auto-commit each change — it edits the working tree and leaves staging and committing to you, so review the diff before committing.
Good to know
Codex CLI is free and open source under the Apache-2.0 license, available on macOS and Linux natively and on Windows (natively via PowerShell or under WSL2). Model usage is not free: you either consume your ChatGPT plan's included Codex allowance or pay per token with an API key. The danger-full-access sandbox mode removes network and filesystem guardrails — use it only on repositories and tasks you fully trust.
Frequently asked questions
- What is Codex CLI?
- Codex CLI is OpenAI's open-source coding agent that runs entirely in your terminal. You point it at a repository, describe a task in plain language, and it reads files, edits them on disk, and runs shell commands — all inside an OS-level sandbox that defaults to no network access and write permissions scoped to your workspace. It is written in Rust.
- Is Codex CLI free?
- The tool itself is free and open source under Apache-2.0, but model usage is not: you either consume your ChatGPT plan's included Codex allowance (Plus, Pro, Business, Edu, or Enterprise) or pay per token with an OPENAI_API_KEY.
- How do I install Codex CLI?
- Install it with npm install -g @openai/codex — it also ships via Homebrew or a one-line shell installer — then run it in a repo, e.g. codex 'Add a retry with backoff to the API client and a test for it'. The same binary works on macOS, Linux, and Windows (natively or via WSL).
- Codex CLI vs Aider?
- One concrete difference: unlike Aider, Codex does not auto-commit each change. It edits the working tree and leaves staging and committing to you, so review the diff before committing.
Related
- Claude CodeAnthropic’s official agentic coding tool that runs in the terminal, IDE, and web.
- AiderOpen-source terminal AI pair programmer that edits files in your Git repo and auto-commits each change, working with Claude, GPT, and other models you bring.
- Gemini CLIGoogle's open-source terminal AI agent powered by Gemini models, with a 1M-token context window and built-in tools.
- Claude Code vs Codex CLI: Terminal Agents Compared (2026)Claude Code vs OpenAI's Codex CLI — autonomy vs sandboxed control, extensibility vs open source, model ecosystems, and which terminal agent fits your work.
- AI Coding Agents in 2026: The Open-Source & CLI EditionCursor and Windsurf vs the open-source agents — OpenCode, Cline, Aider, Codex CLI, and more. Who should bring their own model, and when to stay in the terminal.
- Claude vs GPT vs Gemini for Coding in 2026The three frontier model families compared for real coding work — agentic depth, ecosystem fit, context, and cost shape — plus how to actually choose.
- GooseBlock's open-source, on-machine AI agent that is MCP-native and model-agnostic, with a CLI and desktop app.
- OpencodeThe open-source AI coding agent — a terminal TUI from Anomaly with 75+ model providers, LSP-powered context, parallel agents, and shareable sessions.
- WarpA modern, AI-powered terminal with an agent mode that can run and chain commands across your codebase.