Use Codex for Free: Complete Tutorial for Direct DeepSeek Integration

Install OpenAI Codex for free using DeepSeek API Key with this complete setup guide.
This tutorial shows how to install and configure OpenAI Codex (both CLI and desktop versions) using a DeepSeek API Key, bypassing the need for an OpenAI account or special network access. It covers Node.js environment setup, the critical sandbox freezing workaround using DeepSeek's one-click script, and how the desktop version automatically inherits CLI configuration.
OpenAI's programming Agent Codex has long been seen as a high-barrier tool by many developers — requiring not only an OpenAI account but also dealing with various network access restrictions that discourage many users in China. But in reality, now that DeepSeek natively supports Codex, anyone can get both the CLI and desktop versions of Codex up and running without spending a penny or relying on special network access.
This article is based on a hands-on tutorial by B站 (Bilibili) creator Yongge, organized into a complete "beginner-friendly" installation guide with explanations of key pitfalls.
Why Direct DeepSeek Connection to Codex Matters
Codex officially requires OpenAI account login by default, creating a high network barrier. DeepSeek now provides native compatibility with Codex, meaning you can directly use a DeepSeek API Key to connect to Codex, bypassing both the OpenAI account requirement and network barriers.
From a technical standpoint, Codex CLI is essentially a programming Agent framework with a configurable model backend. It reads local configuration files to determine which model endpoint to call. DeepSeek's one-click script automates the writing of this configuration file, making the entire process require zero manual parameter changes. This is the technical foundation that makes the "zero-cost" solution possible.
Codex's Evolution as a Programming Agent
OpenAI Codex was originally a code generation system fine-tuned from GPT-series models, initially offered as an API service. With the rise of the Agent paradigm, Codex gradually evolved into a programming Agent with autonomous execution capabilities — it can not only generate code snippets but also understand project context, execute terminal commands, read and write the file system, and even perform multi-step code refactoring. The CLI version of Codex is essentially a locally-running Agent runtime that ensures security through sandbox isolation while enabling flexible AI capability integration through a configurable model backend.
How DeepSeek's Compatibility Layer Works
DeepSeek's API interface follows the OpenAI API communication protocol format (including request structure, streaming responses, function calling specifications, etc.), a design known as the "OpenAI compatibility layer." In actual communication, Codex CLI sends standard-format requests to the API endpoint specified in the configuration file, and DeepSeek's server correctly parses them and returns responses in the expected format. This protocol-level compatibility allows a large number of tools built on the OpenAI API to seamlessly switch to the DeepSeek backend — users only need to modify two parameters: the API Key and the Base URL. This is exactly all that the one-click script does behind the scenes.
Codex CLI Installation Steps
Environment Check: Verify Node.js Version
The first step is to verify your local environment. Open PowerShell, check whether Node.js is installed, and ensure the version is higher than 22. If the version meets the requirement, proceed to the next step; if Node.js isn't installed, you'll need to install this prerequisite first.
Codex CLI requires Node.js 22+ due to its underlying technology stack. Node.js 22 introduced several key features: stable API support for native ES Modules, an improved fetch API implementation (used for HTTP communication with model backends), and more comprehensive Worker Threads support. Codex CLI heavily uses these modern JavaScript features to implement asynchronous streaming communication, concurrent task processing, and modular architecture. Using a lower version of Node.js may result in syntax incompatibilities, missing APIs, and other runtime errors that cause installation or startup failures.

One Command to Complete Codex CLI Installation
Once the environment is ready, execute the official installation command. The entire process is very fast — Codex CLI (Codex Elite) installs in about 10 seconds. After successful installation, you can verify it by checking the version information, confirming the CLI is in place.
Generate Configuration Directory and First Launch
After executing the codex command, a welcome screen will automatically appear. The key at this step is choosing the login method: select the third option on the welcome screen, which is "Log in with your own API Key."

Next, you'll need to enter your DeepSeek API Key. Here's an easy-to-miss detail: the API Key cannot be pasted — it must be typed manually character by character. After entering it, select the first option to proceed to the sandbox creation process.
For sandbox mode, it's recommended to start with "non-admin mode" (the second option). The first option requires administrator privileges and is more complex to configure. Get the environment running with non-admin mode first, and adjust later if needed.
Solving Sandbox Freezing: The Biggest Pitfall and Workaround
This is the biggest pitfall in the entire installation process. Creator Yongge discovered during testing that the first Codex launch gets stuck at the sandbox setup phase, with no response for an extended period. Pressing Ctrl+C doesn't interrupt it, and ultimately you can only close the window directly — he wasted 6 minutes stuck at this step.
Technical Reasons for Sandbox Freezing
Codex's Sandbox is a security isolation mechanism designed to prevent the AI Agent from making uncontrollable modifications to the host system when executing code. Sandboxes typically achieve this through file system isolation, network access restrictions, and process permission controls. Admin-mode sandboxes can call system-level APIs (such as Docker containers or Windows Sandbox) to provide stronger isolation; non-admin mode achieves lightweight protection through user-space directory restrictions and privilege reduction. The freeze during first launch is most likely because the sandbox is attempting to download container images or configure system-level virtualization components and encountering network timeouts — a problem especially pronounced in China's network environment.
One-Click Script Workaround
There's no need to panic, because the configuration files have actually already been written at this point. The solution is to directly run the DeepSeek official one-click script:

After running the script, select "1" to use the DeepSeek V4 Flash model. The script will automatically write all configuration files for you — no manual modifications needed whatsoever. When the interface displays Installation Complete, the configuration is done. At this point, type codex and press Enter again, and you can interact with it normally — having it write code, modify code, all without issues.
DeepSeek V4 Flash is a lightweight high-speed inference model from DeepSeek, positioned at the optimal balance point between speed and cost. Compared to the full DeepSeek V4, the Flash version significantly reduces inference latency and token consumption while maintaining relatively high code generation quality. For programming Agent scenarios like Codex that require frequent interaction, low latency means a smoother conversational experience, while low cost means free quotas can support more rounds of usage. Developers with higher code quality requirements can switch to the full DeepSeek V4 or other available models in the configuration file.
The value of this trick lies in replacing the potentially blocking interactive sandbox configuration with scripted automatic configuration, significantly reducing the probability of failure. This is the core of what makes this tutorial truly "beginner-friendly."
Codex Desktop Version Installation and Configuration (GUI)
OpenAI has merged Codex into the ChatGPT desktop app, meaning you can also use a graphical interface version in addition to the command line. This integration reflects OpenAI's product strategy: embedding Codex's programming Agent capabilities into broader conversational interaction scenarios, allowing developers to seamlessly switch between dialogue and code execution without changing tools.
Free Download via Microsoft Store
Open the Microsoft Store, search for "Codex" — the result will show as ChatGPT. Click Free Download and complete the download.

After downloading, double-click to run the installation file. If the system prompts "cannot be accessed," select "Run anyway" to continue. During installation, a ChatGPT work type personalization settings screen will appear — these options don't affect subsequent use, so skipping them is the fastest approach.
Desktop Version Automatically Inherits CLI Configuration
There's a pleasant surprise after the desktop version installation is complete: DeepSeek is already automatically configured. The reason is that the desktop version directly reads the configuration files written during the CLI phase, so there's no need to configure everything again. This design follows the "single source of configuration" principle — the CLI and desktop versions share the same configuration file located in the user directory (typically a JSON or YAML file in the ~/.codex/ directory), and modifications from either side take effect for both.
When the bottom-right of the input box displays a DeepSeek model identifier, the configuration is successful. Click the top-left corner to switch to Codex mode. At this point, both the CLI and desktop versions are fully set up.
Summary: Three Steps to Zero-Cost Codex Usage
The core approach of this solution can be summarized in three points: Use a DeepSeek API Key instead of OpenAI account login, Use the official one-click script to bypass sandbox freezing, and The desktop version automatically reuses CLI configuration.
For developers in China, this means you can experience OpenAI Codex's programming capabilities without special network access or paid subscriptions. Of course, actual code quality and response speed still depend on the chosen DeepSeek model (this tutorial uses V4 Flash), and interested developers can further adjust the configuration according to their needs. Hitting pitfalls isn't scary — find the right shortcuts, and anyone can use cutting-edge tools at low cost.
It's worth noting that the essence of this solution leverages Codex CLI's open architecture and DeepSeek's API protocol compatibility. As more Chinese-developed large models provide OpenAI-compatible interfaces, similar replacement solutions will become increasingly common in the future — not just Codex, but a whole range of development tools built on the OpenAI API including Cursor, Continue, Aider, and others can all connect to domestic models using the same approach, truly achieving localization and cost reduction for development tools.
Related articles

Codex, Cursor, Claude Code: How to Choose Your AI Programming Assistant
In-depth comparison of OpenAI Codex, Cursor, and Claude Code—their core strengths, tradeoffs, and ideal use cases—to help developers choose the right AI programming tool stack.

Public AI with Shared Memory: What Happens When All Users Share One Brain?
An unconventional AI project lets all users share one memory, sparking debate on privacy, security, and collective intelligence. We analyze its design, risks, and future hybrid architectures.

Google Gemini and Pixel Partner with Five Football Clubs: AI Reshapes the Matchday Experience
Google announces Gemini AI and Pixel partnerships with five top football clubs, using real-time data analysis and smart Q&A to transform matchday fan experiences.