
# Codex CLI VPS: run OpenAI Codex on your own server

**A Codex CLI VPS lets OpenAI's coding agent work for hours without your laptop: it edits code, runs tests and builds your project on the server while you check in from the web console.** On 0x.cloud, the s2-4 plan (2 vCPU, 4 GB RAM, 60 GB NVMe) at $15.99/mo fits most projects, and the AI agents image already ships Node, Python, Git, tmux and Docker. Servers run in Warsaw, and your OpenAI account stays yours.


[Create server: s2-4, $15.99/mo](https://0x.cloud/cabinet/create?plan=s2-4)



## Why run Codex CLI on a server

[Codex CLI](https://github.com/openai/codex) is OpenAI's coding agent that runs in your terminal (Apache-2.0 licensed). On a laptop it hits three limits: close the lid and the task stops, the agent can see your personal files, and long builds tie up your work machine. A server fixes all three:

- **Uninterrupted runs.** The session lives in tmux, so closing the console doesn't kill it.
- **Isolation.** The agent edits files and runs commands inside the VPS, not your home directory.
- **A clean test environment.** Docker, databases and preview stacks live on the server.
- **Fast network.** Unmetered traffic at up to 1 Gbps for `git clone`, packages and images.

## Picking a plan for your Codex CLI VPS

OpenAI doesn't publish memory requirements. The CLI ships as a prebuilt binary for Linux x86_64 and arm64 and barely touches the server on its own. Resources go to what the agent runs: `npm install`, compilers, test suites and containers.

| Workload | Plan | Specs | Monthly |
|---|---|---|---|
| Scheduled `codex exec` jobs, small repo | s1-2 | 1 vCPU, 2 GB RAM, 30 GB NVMe | $7.99 |
| Coding agent on a web app with tests | **s2-4** | 2 vCPU, 4 GB RAM, 60 GB NVMe | $15.99 |
| Several sessions, Docker Compose, heavy builds | s4-8 | 4 vCPU, 8 GB RAM, 120 GB NVMe | $31.99 |

Not sure? Bill hourly, work for a day, check `free -h`, then switch to monthly. Delete the server and billing stops right away.

## Codex CLI on Ubuntu: setup in 5 steps

Commands come from the [Codex README](https://github.com/openai/codex) and the [authentication docs](https://learn.chatgpt.com/docs/auth), checked 20.11.2026.

1. **Create a server:** s2-4 with the AI agents image or plain Ubuntu 24.04.
2. **Install Codex CLI** with the official script (or `npm install -g @openai/codex` if you prefer npm):

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

3. **Sign in without a browser.** A server has no GUI, so use device code login. First turn it on in your ChatGPT security settings (in a workspace, an admin does this), or the command fails:

```bash
codex login --device-auth   # open the link on your laptop, enter the code
# or with an API key:
printenv OPENAI_API_KEY | codex login --with-api-key
```

4. **Run the agent in tmux:**

```bash
tmux new -s codex
cd ~/project && codex
# Ctrl+B, then D to detach; the agent keeps working
tmux attach -t codex   # come back later
```

5. **Automate it.** For non-interactive jobs use `codex exec`. It runs in a read-only sandbox by default; `--sandbox workspace-write` allows edits:

```bash
codex exec --sandbox workspace-write "update dependencies and run the tests"
```

The full guide, with Git setup, a repository deploy key and resuming sessions, is at [deploy Codex](https://0x.cloud/deploy/codex).

Heads-up: login tokens are cached in `~/.codex/auth.json` as plain text. Never commit it or hand over a server image that still contains it.

## Common mistakes and fixes

- **`Killed` mid-build.** Out of memory. Add 2 GB of swap or move up a plan.
- **The agent can't `git push`.** No key for the repository. Create a deploy key scoped to that one repo instead of copying your personal key.
- **Session gone after you disconnect.** Codex was started outside tmux. Start with `tmux new -s codex` every time.

## Let your agent create the server

On 0x.cloud, an AI agent (Codex, Claude Code, Cursor, ChatGPT) can check the price and create a server through MCP or the API. Each API key has permissions (read, create, delete) and a monthly spend cap, and `dry_run` returns the exact price without creating anything. Details on the [0x.cloud for AI](https://0x.cloud/ai) page.


```text
Create an s2-4 server with Ubuntu 24.04 on 0x.cloud, install Codex CLI with the official script and tmux if it's missing. Don't log in; I'll run codex login --device-auth myself. Show me the dry_run price first.
```


## Where to run Codex: options compared

| Option | Where code runs | 24/7 | Fits |
|---|---|---|---|
| Codex on your laptop | your computer | only while it's on | short tasks next to you |
| Codex Web (OpenAI cloud) | OpenAI's environment | yes | GitHub repo tasks without your own infra |
| Codex CLI on a 0x.cloud VPS | your VPS | yes | full control, your services, Docker, schedules |

Also using Claude? Compare with [Claude Code VPS](https://0x.cloud/claude-code-vps) or pick a general setup on [VPS for AI agents](https://0x.cloud/vps-for-ai-agents). All plans are on the [pricing page](https://0x.cloud/pricing).

## Codex CLI VPS FAQ

**How do I install Codex CLI on Ubuntu?**
Run the official installer: `curl -fsSL https://chatgpt.com/codex/install.sh | sh`. `npm install -g @openai/codex` works too. Prebuilt Linux binaries exist for x86_64 and arm64.

**How do I log in to Codex on a headless server?**
Turn on device code login in your ChatGPT security settings (it's in beta), then run `codex login --device-auth`, open the link on your laptop and enter the one-time code. For API billing, pipe your key in: `printenv OPENAI_API_KEY | codex login --with-api-key`.

**How much RAM does Codex CLI need on a VPS?**
OpenAI doesn't publish a RAM requirement; the CLI itself is light. Your project's builds, tests and containers set the size. For a typical web project, start with s2-4 (4 GB RAM).

**Can I use my ChatGPT plan with Codex on a server?**
Yes. Sign in with ChatGPT works on a server too, and Codex is included in paid ChatGPT plans. Credentials are cached in `~/.codex/auth.json`, so treat that file like a password.
