How to Install and Use OpenAI Codex CLI Locally?
The advanced reasoning capabilities of OpenAI's latest models are now accessible directly from your terminal via the OpenAI Codex Command-Line Interface (CLI), an open-source tool. This portable coding assistant can read, modify, and run code locally on your machine, accelerating feature development, resolving issues, and aiding in understanding complex code. Unless you opt to share it, your source code never leaves your environment, as the CLI functions locally, as stated by OpenAI. In this article, I will guide you through the installation and usage of OpenAI's Codex CLI locally.
Table of Contents
- Why Codex CLI?
- Approval Modes
- Sandboxing Details
- New codex-mini-latest
- How to Access Codex CLI?
- Inference from Using Codex CLI
- Conclusion
Why Codex CLI?
Codex CLI is tailored for developers familiar with the terminal who desire ChatGPT-level reasoning coupled with the ability to run code, manage files, and iterate, while maintaining version control. Essentially, it’s chat-driven development that comprehends and executes your code. Some of its standout features include:
- No Setup Required: Just bring your OpenAI API key, and you're good to go!
- Lightweight Requirements: Node.js (v22 ) and npm (v10 ) are needed, but the setup is quick and simple.
- Full Auto Mode: Functions within a directory sandbox with network access disabled, ensuring data privacy and security.
- Multimodal Support: Input screenshots or diagrams, and Codex CLI can interpret and replicate the requirements shown in your images.
- Open Source: The tool is entirely open-source, allowing you to examine the codebase and even contribute to its development.
Please note that Codex CLI is still an ongoing experimental project. It may encounter issues, lack features, or undergo significant changes since it is not yet stable.
Also Read: How to Access and Use OpenAI Codex?
Approval Modes
Approval modes dictate the extent of access granted to the AI system (Codex CLI). Three approval modes are available, outlined below:
.responsive-table { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; } .responsive-table table { width: 100%; border-collapse: collapse; border: 1px solid #000; } .responsive-table th, .responsive-table td { border: 1px solid #000; padding: 8px; text-align: left; vertical-align: top; } .responsive-table th { background-color: #f4f4f4; } @media (max-width: 768px) { .responsive-table th, .responsive-table td { padding: 12px; } }
Mode | What the Agent Can Do | When to Use |
---|---|---|
Suggest (default) | Read files. Proposes edits & shell commands, but requires your approval before making changes or executing commands. | Safe exploration, code reviews, learning a codebase. |
Auto Edit | Read and write files automatically. Still asks before running shell commands. | Refactoring or repetitive edits where you want to keep an eye on side-effects. |
Full Auto | Read, write, and execute commands autonomously inside a sandboxed, network-disabled environment scoped to the current directory. | Longer tasks like fixing a broken build or prototyping features while you grab a coffee. |
Sandboxing Details
macOS 12
Codex CLI employs Apple Seatbelt (sandbox-exec) for command sandboxing.
- The majority of the filesystem is kept in a read-only jail, with a few exceptions like $PWD, $TMPDIR, and ~/.codex, which remain writable.
- By default, outbound network access is entirely blocked—even if a child process attempts to use curl, it will fail.
Linux
Sandboxing isn't enabled by default. OpenAI suggests using Docker for sandboxing.
Codex CLI operates inside a lightweight container image, with your repository mounted in the same location for read/write access. A custom iptables/ipset firewall script blocks all outgoing traffic except access to the OpenAI API. This ensures repeatable, predictable execution without requiring root access on the host. To activate this, use the run_in_container.sh script to configure the sandbox environment.
New codex-mini-latest
codex-mini-latest is a fine-tuned version of o4-mini specifically for use in Codex CLI. It boasts a context window of 200k and can produce up to 100,000 tokens. codex-mini-latest’s pricing falls between GPT-4.1 and o4-mini, and the following image shows the pricing of input, cached input, and output per million tokens.
How to Access Codex CLI?
Follow these straightforward steps to access Codex CLI:
-
Navigate to a project you’re working on. If you wish to test it with a dummy repository, consider cloning this repository to begin experimenting with Codex CLI. GitHub Repository link
Use the command “git clone //m.sbmmt.com/link/851612d3c194dc64724360831ff04bf8” to clone this repository. Alternatively, you can use a smaller repository.
Change to the directory containing the repository. Use the command “cd
” to navigate to that directory. -
Install Codex CLI Now that we’re prepared to start accessing Codex CLI. Let’s install it. Use the command:
npm install -g @openai/codex – this command will install Codex CLI globally on your system. -
Obtain the API OpenAI offers $5 worth of codex-mini-latest API for Plus users and $50 worth of credits for Pro users. Redeem this by using the command:
codex — login
This will prompt you to log in or enter an API key.
Sign in with Codex CLI using ChatGPT
-
Successful Redemption MessageAfter successfully signing in to Codex CLI, you should see a successful redemption message in your terminal as well as your OpenAI dashboard.
-
Verify Codex CLI Access in TerminalStart accessing Codex CLI:
-
Scan your repositoryAfter 3 entire minutes of scanning the repository, it provided a comprehensive response about the repository.
-
Make changes in the repoLet’s now ask Codex CLI to make some changes.
Prompt: “Enhance the chainlit application app.py, this has the persona of warren buffet:
1. Add search tools
2. Improve the code quality, 3. Enhance the chainlit application”
Output:
After running the Codex CLI for approximately 15 minutes, and after reviewing and approving the changes made by the agent, the execution concluded.
These are some screenshots during the Codex CLI agent execution.
Also Read:
The above is the detailed content of How to Install and Use OpenAI Codex CLI Locally?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

ArtGPT
AI image generator for creative art from text prompts.

Stock Market GPT
AI powered investment research for smarter decisions

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

The project, dubbed “FOMC in silico,” digitally recreates a meeting of the Federal Open Market Committee—the decision-making arm of the U.S. central bank—using AI agents to represent actual board members. The research team fed each agent data on indi

At the same time, traditional storage protocols are being replaced by newer technologies that better meet the needs of scalable, high-performance-driven AI workloads. Storage solutions for AI are increasingly choosing object storage over traditional block storage and file storage. This shift is ironic because object storage was originally developed as a scalable, durable and low-cost platform, mainly for conventional backups, archives, media content, and cloud-scale data lakes. However, unlike traditional file and block storage systems that are overwhelmed by the demands of large-scale parallel processing, object storage provides the scale-out capabilities and performance performance required by AI applications. Founded more than ten years ago, MinIO is an early leader in the object storage market. The company will

Reads an introduction to the ever-expanding roster of nominees, featuring legal filings packed with made-up court rulings, phony books attributed to real authors, and an Airbnb host using AI to fabricate images suggesting a guest caused damages they

A Waymo vehicle without any passengers was traveling along Rural Road near Arizona State University in Tempe when it began slowing down to make a right turn into a parking lot—likely preparing to pick up its next rider. Waymo confirms the turn signal

The psychological impact of this transformation is profound. For years, assistive technology has been cumbersome, stigmatizing, and rigid—forcing users into a one-size-fits-all mold. But AI is rewriting that story, delivering personalized solutions t

Interestingly, new studies reveal that one of the most common uses for AI chatbots today is emotional and mental health support. Many users find it easier to open up about deeply personal matters they might hesitate to discuss with friends, family, o

Whether that’s achievable remains to be seen, but an assessment by Forbes of the latest version of FSD found that it remains error-prone. During a 90-minute test drive in Los Angeles, in residential neighborhoods and freeways, the 2024 Model Y with T

The company announced a 359% surge in its order backlog during the Q1 2026 earnings call, triggering a 36% spike in its stock value that day. This milestone propelled Ellison—owner of over 40% of the company’s shares—to the top of the Forbes Billiona
