
curl or npm, sign in from a headless server, and configure sandbox modes before letting it work with anything important.There’s also a version-related detail worth knowing. The old --full-auto flag is deprecated and displays a warning, so use --sandbox workspace-write instead. Likewise, codex mcp-server has been replaced by the Codex app server.
npm config get prefix
codex –version
codex doctor –summary
If you prefer using Node.js, install Node.js and npm first. The package manager command depends on your distribution, so use the one that matches your system.
Install Codex CLI on Linux
Two more options become useful when you put Codex into scripts. --json outputs newline-delimited JSON events instead of formatted text, making it easy to pipe the output into jq and use the results in your script. --skip-git-repo-check allows Codex to run in a directory that isn’t a Git repository, which it otherwise refuses to use.
It’s easy to install an AI agent, run it with all the guardrails turned off, and only check the sandbox settings after it has changed a configuration file you needed. Codex provides three sandbox levels along with a separate approval policy. The combination you choose determines what it can access and modify.
curldownloads the install script over HTTPS.-fmakescurlfail on server errors instead of saving an HTML error page.-sruns silently, while-Sshows real error messages.-Lfollows redirects used by the download endpoint.| shsends the downloaded script directly to the shell for execution.
codex login status
codex: command not found
codex exec –sandbox read-only -o /tmp/audit.md “Summarise every systemd unit in this repo that runs as root”
If you want to keep your code and requests on your own hardware, --oss lets Codex use a local model provider instead of OpenAI’s hosted models:
codex –oss –local-provider lmstudio
npm install -g @openai/codex
The quickest way to install Codex CLI is with the official install script. It downloads a prebuilt binary and places it on your PATH.
codex exec resume –last
You’ve also seen how codex exec lets you run tasks without the interactive terminal UI, making it useful for scripts and automation. Here’s a good way to start. Pick a repository you know well, run:
The safest place to use this flag is inside a container or a throwaway VM that is already isolated at the operating-system level. On a machine containing real data, workspace-write with on-request gives you a good balance of speed and protection.
Codex installed successfully on your server, share this guide with the next person who’s about to run an install script without checking it first.Sign In From a Headless Server
Codex separates two questions that are easy to mix up: What can the agent access? And when should it stop and ask you?
codex –sandbox read-only
curl -fsSL https://chatgpt.com/codex/install.sh -o codex-install.sh
sudo apt install nodejs npm
If the task genuinely requires access to another directory, grant access to that directory explicitly instead of weakening the sandbox:
What’s the first task you’d trust Codex with on a real server, and what’s the one you wouldn’t? Share it in the comments. The boundaries people set around these tools can be just as interesting as the tools themselves.
Sandbox Modes: The Setting That Actually Matters
codex –oss –local-provider ollama
codex –sandbox workspace-write –ask-for-approval on-request
codex –sandbox workspace-write –add-dir /var/www/
Whichever installation method you use, verify that Codex is available:
For everyday work in a repository, the combination worth remembering is:
If a scripted run stops partway through and you want to continue instead of starting again, use:
The first time you run codex, it asks you to sign in. On a desktop, Codex opens your browser and completes the ChatGPT OAuth sign-in automatically.
The Flag You Shouldn’t Reach For
So before getting into the useful stuff, we’ll install Codex, sign in, and then look closely at the flags that control what it can and cannot touch.
Run /status as soon as you start a session. It’s the quickest way to confirm that Codex is using the sandbox you expect. It can also help catch situations where an existing ~/.codex/config.toml setting is overriding the flags you passed on the command line.
--yolo on the production box, and share the reason why it’s risky, not just the flag.Slash Commands Worth Knowing
Once you’re inside the terminal UI, type / to open the command popup. These are the commands you’ll use most often:
/statusshows the active model, approval policy, writable roots, and how much context you have left./diffshows the Git diff of everything Codex changed, including files that Git isn’t tracking yet./reviewasks Codex to review your working tree and look for behavior changes or missing tests./compactsummarizes the conversation so far and frees up context during a long session./permissionschanges the approval preset without restarting Codex./modelswitches the active model before you start a more demanding task.
Codex CLI is a local agent that works directly in your terminal. It can read your repository, suggest and make edits, run ls command, grep command, execute your test suite, and show you a diff of the changes it made.
Running Codex Against a Local Model
You’ve now installed codex using a script, npm package, or static binary, signed in from a headless server with the device code flow, and learned how --sandbox and --ask-for-approval control what the agent can access and when it needs your approval.
codex login –device-auth
On Ubuntu/Debian:
Run Codex Non-Interactively With codex exec
The most common problem immediately after installation is a shell that can’t find the codex command.
codex –version
For a sysadmin, that last part is especially important. Codex isn’t just a chat window that prints code for you to copy and paste; it can actually run commands in your shell and make changes on your system. That’s why the sandbox section below is worth reading carefully.
Codex is included with ChatGPT Plus, Pro, Business, Edu, and Enterprise plans, so signing in with your ChatGPT account is the usual approach. If you’re using Codex in automation instead, you can provide an API key through an environment variable:
The examples in this guide were tested on Ubuntu 26.04 and RHEL 10. The commands should also work on any modern Linux distribution running on a 64-bit x86 or ARM system.
Tell Codex Your Rules With AGENTS.md
sudo dnf install nodejs npm
printenv OPENAI_API_KEY | codex login –with-api-key
The approval policy controls the second question with --ask-for-approval, or -a:
When Codex Won’t Start
Codex includes its own diagnostic command, which checks your installation, configuration, authentication, runtime, Git, and terminal setup in one pass:
Once Node.js and npm are installed, install Codex CLI globally:
Codex reads an AGENTS.md file from the directory where it is working and uses it as a set of standing instructions. You can create a starter file from inside a Codex session with:
Once you’re happy with the instructions, commit the AGENTS.md file to your repository. That way, you don’t have to explain the same project conventions at the start of every session.
Everything Else
Codex also has a --dangerously-bypass-approvals-and-sandbox flag, aliased as --yolo, which disables both approval prompts and sandboxing. The name is a pretty good warning.
The terminal UI works well when you’re sitting at the keyboard. For cron jobs, CI pipelines, and other tasks that need to run without a person watching, use codex exec, which is also available as codex e.
That last part comes with an important warning. Piping a remote script directly into sh means the shell executes whatever the server sends. If you’re installing Codex on a system you don’t own or manage, download the script first, review it, and then run it:
Conclusion
/init
The sandbox controls the first question with --sandbox, or -s for short:
curl -fsSL https://chatgpt.com/codex/install.sh | sh
On a server you connect to over SSH, there’s usually no browser available to open. This is where the device authentication flow comes in: