Black Friday: Save 10% for life on all of our VPS plans, now through Cyber Monday

10% off on selected plans for as long as you keep the service · new orders · up to 10 uses per customer · ends Dec 1, 2026, 12:00 AM EST.

See plans
Guideschevron_rightServers

Servers · 8 min read · Updated

How to Run Claude Code and Codex on a VPS

To run AI coding agents on a VPS, create a normal user on an Ubuntu server with at least 4 GB of RAM, install Claude Code with curl -fsSL https://claude.ai/install.sh | bash and the Codex CLI with npm install -g @openai/codex, sign in without a browser (Claude Code prints a link and takes back a code; Codex has codex login --device-auth), and start each agent inside tmux so it keeps working after you disconnect. The agent then works on a server that never sleeps, away from the files and keys on your own computer; our smallest VPS with 6 GB is $37.50 a month.

Why Run Coding Agents on a Server

  • It keeps going: long tasks finish while your laptop is closed or offline.
  • Reach it from anywhere: any device with SSH, a phone included, can check in on a session.
  • A smaller blast radius: the agent sees the server's files and keys, not your personal machine's.
  • Several at once: one tmux window per task or repository. More agents and bigger builds need more memory; a dedicated server gives a whole team fast cores nobody else shares.

1. Prepare the Server

After securing the server and setting up SSH keys, create a user for the agents and install the tools they will use:

sudo adduser dev
sudo apt update && sudo apt install -y git tmux build-essential bubblewrap socat
sudo -iu dev

bubblewrap and socat are what Claude Code's sandbox needs on Linux. Give this user a GitHub deploy key or a fine-grained token limited to the repositories the agents work on, not your personal key.

2. Install and Sign In to Claude Code

curl -fsSL https://claude.ai/install.sh | bash
claude --version
claude doctor          # checks the installation

Run claude in a project folder. With no browser on the server, press c to copy the login link, open it on your own computer, and paste the code it shows at the Paste code here if prompted prompt. Claude Code needs a Pro, Max, Team, Enterprise or Console account. On Linux the credentials are kept in ~/.claude/.credentials.json, readable only by this user. The native install updates itself in the background (setup docs).

Turn on the sandbox with /sandbox inside Claude Code. It confines the shell commands the agent runs; file edits and web fetches still go through Claude Code's own permission checks (sandboxing docs).

3. Install and Sign In to Codex

curl -fsSL https://chatgpt.com/codex/install.sh | sh
# or, with Node.js installed: npm install -g @openai/codex
codex login --device-auth

Device-code sign-in is in beta and has to be allowed in your ChatGPT security settings or workspace permissions. Two other ways work on a server:

# Normal browser login, through an SSH tunnel from your computer:
ssh -L 1455:localhost:1455 dev@203.0.113.10
codex login            # open the printed address in your local browser

# Or an API key:
printenv OPENAI_API_KEY | codex login --with-api-key

Codex keeps its login in ~/.codex/auth.json in plain text unless you choose the system's credential store, so treat that file like a password. Its default sandbox, workspace-write, lets it edit the project and run routine commands there (Codex sandboxing).

4. Keep Sessions Running in tmux

tmux new -s app          # start a named session
cd ~/projects/app && claude
# Ctrl+B then D detaches; the agent keeps working
tmux ls                  # list sessions later
tmux attach -t app       # pick up where you left off

5. Run Tasks Without Watching

For scheduled or scripted work, both agents have a non-interactive mode. Claude Code takes a prompt with -p and the tools it may use without asking:

claude -p "Run the test suite and fix any failures" --allowedTools "Bash,Read,Edit"

Codex has codex exec for the same purpose. Run either from a systemd timer or a CI job; for CI on your own server, see self-hosted GitHub Actions runners.

Keep It Safe

  • Keep the permission prompts. Claude Code's bypassPermissions mode and Codex's danger-full-access sandbox are for throwaway servers or containers only.
  • Keep production secrets off this server; give the agent test credentials and a staging database.
  • Back up your work: push branches often and keep server backups, so a bad command costs minutes, not days.
  • Running models yourself instead of a hosted API? Pair the agents with a model on a GPU server or gpt-oss.

Claude, Claude Code, OpenAI, Codex and ChatGPT are trademarks of their respective owners. Virteche is not affiliated with or endorsed by them. Details about their products come from their public documentation as of the date at the top of this guide.

Common Questions

  • Can I run Claude Code on a VPS?

    Yes. Claude Code supports Ubuntu 20.04 and newer and Debian 10 and newer, with 4 GB of RAM or more. Install it with the native installer, run claude, and sign in by opening the login link on your own computer and pasting back the code.

  • How do I sign in to Codex on a server without a browser?

    Use codex login --device-auth, which shows a code to enter on another device; it is in beta and must be allowed in your ChatGPT security settings. Alternatives are forwarding port 1455 over SSH for the normal login, or piping an API key into codex login --with-api-key.

  • Do the agents keep running when I disconnect?

    Only if you start them inside tmux (or screen). Detach with Ctrl+B then D, close your laptop, and reattach later with tmux attach from any device that can reach the server over SSH.

  • Is it safe to let an agent run commands on my server?

    Safer on a separate server than on your own computer. Keep the default approval modes, turn on the sandbox, give the server only the keys it needs for the repositories it works on, and keep backups. Modes that skip permission checks belong only on a disposable server or container.

Plans and prices

VPS Plans

KVM servers with full root access: a workspace your agents can run on all day.

See all plans
  • Bronze

    3 vCPU · 6 GB RAM · 75 GB NVMe

    2 TB transfer

    $37.50/mo

    Configure inAshburnDallas
  • Silver

    4 vCPU · 8 GB RAM · 100 GB NVMe

    4 TB transfer

    $46.50/mo

    Configure inAshburnDallas
  • Gold

    6 vCPU · 12 GB RAM · 150 GB NVMe

    6 TB transfer

    $60.00/mo

    Configure inAshburnDallas
  • Diamond

    8 vCPU · 16 GB RAM · 200 GB NVMe

    8 TB transfer

    $73.50/mo

    Configure inAshburnDallas

Network port: 10 Gbps in Ashburn, VA, 50 Gbps in Dallas, TX. Pick the location when you configure.

Keep Reading

All guides