Home / Blog / How to run Codex 24/7 in the cloud (Codex CLI hosting explained)
Codex works as long as your terminal lives. Fix that.

How to run Codex 24/7 in the cloud (Codex CLI hosting explained)

OpenAI's Codex CLI is an interactive terminal agent. Close the terminal, drop the SSH connection, or let your laptop sleep, and the run dies with it. Here is how to give Codex a machine that never sleeps: tmux, a cheap VPS, or a managed box with your own ChatGPT login.

Hivra team15 July 20268 min read

The problem: Codex lives and dies with your terminal

The Codex CLI runs as a child of your shell. That gives it three failure modes that have nothing to do with the agent itself:

  • Laptop sleep. Lid closes, the OS suspends everything, Codex stops mid-task.
  • SSH drop. Running Codex on a remote machine? A dropped connection sends SIGHUP to your shell and Codex dies with it.
  • Closed terminal. Quit the app, lose the process.

None of these are Codex bugs. Any interactive CLI has the same constraint: it needs a live terminal on a machine that stays awake.

Worth repeating because it trips people up: tmux on your laptop does not beat laptop sleep. tmux protects against disconnects. It cannot keep a suspended machine computing. The process has to live somewhere that never sleeps. Not sure whether your current setup has one of these gaps? Run it through the agent survival check.

Fix 1: tmux on an always-on machine

If you have a desktop, home server, or VPS that stays up, tmux keeps your Codex session alive across every disconnect:

bash
# Start a named session and launch Codex inside it tmux new -s codex codex # Detach without killing anything: press Ctrl+b, then d # Reattach later, from anywhere tmux attach -t codex

The session runs on the server, not in your terminal app. Your connection can drop, your laptop can sleep, and Codex keeps working. screen -S codex does the same job if you prefer the older tool (detach with Ctrl+a d, reattach with screen -r codex).

Fix 2: codex exec for headless one-shot runs

Codex has a non-interactive mode built in. codex exec takes a prompt, runs the task without the interactive UI, and exits. Combine it with nohup and the run survives your logout:

bash
nohup codex exec "fix the failing tests and open a PR" > codex-run.log 2>&1 & # Watch progress tail -f codex-run.log

Right tool for fire-and-forget jobs. Wrong tool when you want to steer the agent mid-task. For an interactive session you can leave and rejoin, use tmux.

Fix 3: the DIY VPS route

A small VPS costs $5-10/month and runs the Codex CLI fine. The setup:

bash
# 1. SSH in ssh root@your-vps-ip # 2. Install Node.js, then the Codex CLI curl -fsSL https://deb.nodesource.com/setup_22.x | bash - apt-get install -y nodejs npm install -g @openai/codex # 3. Authenticate with your ChatGPT account codex # 4. Run inside tmux so it survives disconnects tmux new -s codex codex

Detach and walk away. The agent keeps working on the server.

The hidden costs of DIY, stated plainly:

  • Setup and auth friction. The ChatGPT login flow on a headless box means shuttling URLs between machines. Budget an hour or two total.
  • Maintenance. Node updates, CLI updates, OS patches, disk cleanup. All yours now.
  • Security. A public box with your logged-in agent on it. SSH keys only, firewall on. Also yours.
  • No interface. SSH is the whole experience. No browser view, no file browser, nothing friendly on a phone.

Fix 4: managed Codex hosting

Hivra runs the official OpenAI Codex CLI on a private virtual machine provisioned for you. Unmodified, straight from upstream. What the product actually ships:

  • Your own ChatGPT login. After launch, the box asks you to sign in with your own ChatGPT account. Hivra never sees or stores your OpenAI credentials.
  • Browser access to the session. Terminal, files, and skills tabs wrap the standard CLI, so you can check a running task from any device.
  • Optional live self-hosted browser. Turn on browser automation and the Codex box gets a real Chrome instance the agent can drive.
  • Always-on infrastructure. The VM stays up. No tmux required, though the terminal tab is right there if you want it.

Launch from the Codex agent page. Takes about 5 minutes.

Plan facts: Codex launches on the free tier ($0, one agent, 0.5 vCPU and 1 GB RAM). Free-tier agents sleep after 4 idle days and skip browser automation. For genuinely always-on with browser automation, Pro is $9.99/month. Numbers on the pricing page.

DIY vs managed

DIY VPS + tmuxHivra managed
Cash cost$5-10/mo$0 free tier, $9.99/mo Pro for always-on
Setup time1-2 hours~5 minutes
LoginYour ChatGPT accountYour ChatGPT account, entered inside the box
InterfaceSSH terminal onlyBrowser: terminal, files, skills
Agent browser automationYou install and maintain itOptional toggle on the Codex box
Updates, patching, securityYouHandled
Root access to the boxYesManaged VM, resize CPU/RAM in the dashboard

Both routes end in the same place: the official Codex CLI, on your own OpenAI account, running around the clock. The difference is who runs the server.

Pick your route

  • One overnight task: nohup codex exec "..." on any machine that stays awake.
  • You own an always-on machine: tmux. Free and done in a minute.
  • Permanent setup, you like server work: $5-10/month VPS plus tmux.
  • Permanent setup, zero server work: deploy Codex on Hivra, sign in with ChatGPT, close your laptop.
Common questions

Can I run the Codex CLI on a server?

Yes. Install Node.js, run npm install -g @openai/codex, authenticate with your ChatGPT account, and start it inside tmux so it survives SSH drops. Any small $5-10/month VPS handles the CLI itself.

Does Codex keep running when I close my terminal?

Not by default. The CLI is a child of your shell and dies with it. Run it inside tmux or screen on an always-on machine, use codex exec with nohup for one-shot headless runs, or use a managed box that stays up.

Do I need an OpenAI API key to run Codex in the cloud?

On Hivra you sign in with your own ChatGPT account inside the box after launch, the same login the CLI uses on your laptop. Hivra never sees or stores your OpenAI credentials.

How much does 24/7 Codex hosting cost?

DIY: $5-10/month for a small VPS plus your setup and maintenance time. Managed on Hivra: Codex launches on the free tier, and the Pro plan at $9.99/month keeps agents always-on with browser automation available.

Is the hosted Codex modified in any way?

No. Hivra runs the official OpenAI Codex CLI unmodified on a private VM. The terminal, files, and skills tabs are a convenience layer around the standard CLI.

Can hosted Codex use a browser?

Yes, optionally. The Codex box on Hivra can run a live self-hosted browser (a real Chrome instance on the VM) that the agent drives for web tasks. It is a toggle, off by default on the free tier since free plans exclude browser automation.

Deploy in 5 minutes.

7-day money-back guarantee. BYO AI key. From $9.99/mo.

Start Now
Related reading
How to keep Claude Code running 24/7Best VPS for Hermes Agent in 2026How much does it cost to run an AI agent?BYO API key: what it means and why it mattersFeature: Browser automation