Install Codex CLI on an Ubuntu server: from the console to your first task

· 0x.cloud Team

Install Codex CLI on an Ubuntu server: from the console to your first task

To install Codex CLI on Ubuntu, run one command: curl -fsSL https://chatgpt.com/codex/install.sh | sh. It drops a prebuilt binary in ~/.local/bin with no Node.js required. Then sign in with a device code (no browser on the server), install bubblewrap for the sandbox, and run the agent inside tmux so it keeps working after you disconnect. Commands match the official docs for Codex CLI 0.171.0 (the stable release on Nov 20, 2026) on Ubuntu 24.04.

Want an AI agent to prepare the server? Paste this into Claude Code, Cursor or ChatGPT with the 0x.cloud MCP connected:

Prompt for an AI agent

Create an s2-4 server with Ubuntu 24.04 on 0x.cloud. Show me the dry_run price first and wait for my "yes". Then, with run_command, create a sudo user called dev, install Codex CLI with the official script https://chatgpt.com/codex/install.sh, install bubblewrap and the bwrap-userns-restrict AppArmor profile, and install tmux and git. Don't log in to Codex: send me the codex login --device-auth command and I'll sign in myself.

Requirements and plan

Codex CLI is OpenAI's coding agent for the terminal. The model runs in OpenAI's cloud; your server runs whatever the agent executes: reading code, tests, builds and containers.

What you need Minimum Comfortable
Server 2 vCPU, 4 GB RAM, 60 GB NVMe (s2-4, $15.99/mo) 4 vCPU, 8 GB RAM (s4-8, $31.99/mo)
OS Ubuntu 20.04+ or Debian 10+ Ubuntu 24.04 LTS
Git 2.23+ for the built-in PR helpers same
Account ChatGPT plan or OpenAI API key same

The 4 GB minimum (8 GB recommended) comes from the openai/codex repository docs. An s2-4 handles Codex, git and tests for a typical project. If the agent spins up Docker with a database or builds a large frontend, pick s4-8. Sizing tips are on Codex VPS hosting.

On 0x.cloud the "For AI agents" image already ships Codex (installed with npm), Claude Code, Node, Python, Git, tmux and Docker. Still install bubblewrap and the AppArmor profile for the sandbox as shown below.

You can start on hourly billing: s2-4 is $0.109520 an hour ($15.99 / 730 × 5) and never more than $15.99 in a calendar month. Setup is $0. Delete it and the remainder returns to your balance.

Deploy to 0x.cloud

Prepare the server

Open the web console of the server in your cabinet and log in as root.

Don't run the agent as root. Create a regular user:

adduser dev
usermod -aG sudo dev
su - dev

Update the system and install the tools:

sudo apt update && sudo apt upgrade -y
sudo apt install -y git tmux curl bubblewrap

Codex's Linux sandbox uses bubblewrap (the bwrap command) to run the agent's commands with limited filesystem access. Check it with bwrap --version, which prints a version number.

Close everything except SSH:

sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status

Expect Status: active and an OpenSSH ALLOW Anywhere line.

Install Codex CLI on Ubuntu: script, npm or binary

Option 1. Official script (recommended).

curl -fsSL https://chatgpt.com/codex/install.sh | sh
source ~/.bashrc
codex --version

The script downloads the latest release, verifies its SHA-256 checksum, places it at ~/.local/bin/codex and adds that directory to your PATH if needed. codex --version should print codex-cli 0.171.0 or newer.

Option 2. npm. Use it if Node.js is already installed (it is on the "For AI agents" image):

sudo npm install -g @openai/codex
codex --version

Option 3. Release archive. GitHub releases include codex-x86_64-unknown-linux-musl.tar.gz. Extract it, rename the file to codex and move it to /usr/local/bin.

There's no codex package in Ubuntu's apt repositories, so sudo apt install codex won't work. Ignore guides that suggest pip either.

Fix the sandbox on Ubuntu 24.04

Ubuntu 24.04 restricts unprivileged user namespaces through AppArmor, so Codex may warn that it can't create one. OpenAI's documented fix:

sudo apt install -y apparmor-profiles apparmor-utils
sudo install -m 0644 /usr/share/apparmor/extra-profiles/bwrap-userns-restrict /etc/apparmor.d/bwrap-userns-restrict
sudo apparmor_parser -r /etc/apparmor.d/bwrap-userns-restrict

The profile allows namespaces for bwrap only instead of disabling the restriction system-wide. Check: start codex in a project folder; the user namespace warning should be gone. OpenAI's docs treat turning the restriction off globally with sysctl as a last resort.

Log in on a headless server

Option 1. Device code (ChatGPT plans). Enable device code login in your ChatGPT security settings first (workspace admins control it for business accounts). Then:

codex login --device-auth

Open the printed link on your laptop, sign in and enter the one-time code. Confirm with codex login status.

Option 2. OpenAI API key (pay per token).

read -s OPENAI_API_KEY && export OPENAI_API_KEY
printenv OPENAI_API_KEY | codex login --with-api-key

read -s keeps the key off the screen and out of your shell history. For long-term storage see how to store API keys on a server.

Option 3. Copy an existing login. Run codex login locally, then, logged in as dev in the web console, paste the contents of your ~/.codex/auth.json into ~/.codex/auth.json on the server.

auth.json holds access tokens. Treat it like a password.

Configure ~/.codex/config.toml

User settings live in ~/.codex/config.toml; project settings go in .codex/config.toml inside the repo. A safe baseline for a server:

approval_policy = "on-request"
sandbox_mode = "workspace-write"
model_reasoning_effort = "medium"

workspace-write lets the agent edit files and run routine commands inside the working folder, and on-request makes it ask before stepping outside. danger-full-access removes all boundaries; only use it on a throwaway server. MCP servers, including the 0x.cloud MCP, are configured in the same file: see connect 0x.cloud MCP to Codex.

Keep Codex running with tmux

A regular process dies when you log out. tmux keeps the session alive on the server:

tmux new -s codex
cd ~/projects/my-app
codex

Detach without stopping the agent with Ctrl+B, then D. Reattach with tmux attach -t codex. More shortcuts in our tmux guide.

Scheduled jobs with codex exec

For recurring work (nightly log triage, dependency bumps) use non-interactive mode. codex exec runs in a read-only sandbox by default:

cd ~/projects/my-app
codex exec --sandbox workspace-write -o ~/codex-report.md "update dependencies and run the tests"

-o writes the final message to a file, so the command works well from cron. The old --full-auto flag is no longer supported; use --sandbox workspace-write instead.

Update Codex CLI

curl -fsSL https://chatgpt.com/codex/install.sh | sh
codex --version

Rerunning the script installs the latest stable release. For npm installs: sudo npm install -g @openai/codex@latest. Codex ships several releases a week, so update at least monthly.

Back up your setup

  1. Code. The agent works in a git repo. Push after every task.
  2. Codex settings. The ~/.codex folder holds config.toml, rules and session history:
tar czf ~/codex-config-$(date +%F).tar.gz --exclude='auth.json' -C ~ .codex

auth.json is excluded on purpose: logging in again after a restore is simpler and safer. On 0x.cloud, take a snapshot ($0.99/mo) before experimenting with danger-full-access, or turn on automatic backups (7 daily copies, +20% of the plan price).

Common errors

Symptom Cause and fix
codex: command not found ~/.local/bin isn't in PATH. Run source ~/.bashrc or reconnect
User namespace warning The bwrap-userns-restrict AppArmor profile isn't loaded. See the sandbox section
codex login waits for a browser Use codex login --device-auth
Device code option missing Device code login is off in ChatGPT security settings
Codex refuses to run outside git Run git init, or pass --skip-git-repo-check if you trust the environment
Agent stopped when you logged out Run it inside tmux
Builds fail with out-of-memory Move to s4-8 or add swap

Official docs: Codex CLI and Codex authentication. Comparing agents? The Claude Code VPS install guide follows the same pattern with a different login.

0x.cloud servers are in Warsaw, and support answers in about 30 minutes on average during business hours (06:00–20:00 UTC). If the agent wrecks the system in danger-full-access mode, an OS reinstall costs $0.

FAQ

Does Codex CLI need Node.js? Not with the official install script, which downloads a prebuilt binary. You only need Node.js if you install the @openai/codex package with npm.

How do I log in to Codex on a server without a browser? Turn on device code login in your ChatGPT security settings, then run codex login --device-auth and enter the one-time code on your own computer. You can also sign in with an API key using codex login --with-api-key.

How do I update Codex CLI? Rerun curl -fsSL https://chatgpt.com/codex/install.sh | sh. If you installed with npm, run sudo npm install -g @openai/codex@latest.

How much RAM does Codex CLI need? OpenAI lists 4 GB minimum and 8 GB recommended. The model runs in OpenAI's cloud; the RAM goes to your project's builds, tests and containers.

Why does Codex say it can't create a user namespace? Ubuntu 24.04's AppArmor restricts unprivileged user namespaces. Install apparmor-profiles and apparmor-utils, copy the bwrap-userns-restrict profile to /etc/apparmor.d and load it with apparmor_parser.

Deploy to 0x.cloud