How to run Codex on a remote server
Running Codex on a remote machine means it keeps working when your laptop doesn’t. Here’s the do-it-yourself setup, and what to watch for.
Published
What you need
- A Linux machine that stays on: a VPS, a cloud VM or a desktop at home.
- SSH access to it, with a key.
- Node.js on the server, and your repositories.
- Your OpenAI or ChatGPT account for Codex.
1. Install Codex on the server
ssh my-server
npm install -g @openai/codex
Then sign in. On a server with no browser, follow the Codex docs for signing in on a headless machine.
2. Bring your code
Clone your repository and set up Git so Codex can commit:
git clone git@github.com:you/your-repo.git
cd your-repo
You’ll need a deploy key or an SSH key on the server that GitHub accepts.
3. Run Codex inside tmux
tmux new -s codex
codex
# detach with Ctrl-b then d
Codex keeps working after you disconnect. Reattach from any device with tmux attach -t codex.
4. Keep it healthy
- Memory: watch it with
free -h. If the agent dies overnight, it’s often the kernel killing a process that ran out of memory. Checkdmesgfor “Out of memory”. - Disk:
node_modules, build caches and Docker images fill small disks fast. Check withdf -h. - Restarts: after an OS update or a reboot, tmux sessions are gone. Start them again.
- Secrets: keep API keys out of your shell history and out of the repo.
The managed alternative
If you’d rather not look after a server, Cube gives you an always-on Linux computer with a Mac app. Sign in with GitHub, install Codex from the list, and every task gets its own worktree and a place in the sidebar. SSH is set up for you (ssh cube), and you can check in from your phone.
Questions
Can Codex run on a headless Linux server?
Yes. The Codex CLI runs in a terminal, so it works over SSH on a Linux server. Signing in without a browser on the server takes an extra step; the Codex docs describe the options.
How much server do I need for Codex?
Codex itself is light, since the model runs on OpenAI’s side. What needs memory is everything the agent runs: installs, builds, test suites and dev servers. Very small instances often run out of memory on real projects.
Why does Codex stop when I close my SSH connection?
Processes started in an SSH session end when it closes. Run Codex inside tmux or screen so the session survives the disconnect.