AI Agents

Run Claude Code & Codex on a cloud VPS

Claude Code (by Anthropic) and Codex (OpenAI's coding CLI) are terminal-based agentic coding assistants — they read your repo, edit files, run commands, and iterate toward a goal. Running them on a remote VPS instead of your laptop means an always-on, powerful box with plenty of CPU and RAM, reachable from any device over SSH or a web terminal. Your laptop stays free, long builds keep running while you're away, and you bring your own API key. This guide walks you through provisioning a server and installing both CLIs.

Provision a VPS

Start with Ubuntu 22.04+ and at least 2 GB RAM (4 GB+ recommended for large repos and heavy builds). Both CLIs run on Node.js 22, so install a current LTS from NodeSource:

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

# Install Node.js 22 LTS via NodeSource
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt install -y nodejs

# Verify
node --version   # v22.x.x
npm --version

Install Claude Code

Install Anthropic's Claude Code globally with npm, then authenticate by exporting your ANTHROPIC_API_KEY. Run the claude command from inside the project directory you want it to work on:

npm install -g @anthropic-ai/claude-code

# Authenticate (BYO Anthropic key)
export ANTHROPIC_API_KEY="sk-ant-..."

# Run it inside your project directory
cd ~/my-project
claude

Claude Code operates on the working directory you launch it in — it reads the files there, proposes edits, and runs commands with your confirmation.

Install Codex

OpenAI's Codex CLI installs the same way. Set your OPENAI_API_KEY, then run codex from your repo:

npm install -g @openai/codex

# Authenticate (BYO OpenAI key)
export OPENAI_API_KEY="sk-..."

# Run it inside your project directory
cd ~/my-project
codex

Use it from anywhere

SSH into the box from any laptop, desktop, or even a tablet, then launch either CLI:

ssh user@your-server
cd ~/my-project
claude      # or: codex

Because the agent runs on the server, a long task keeps going even if your connection drops. Wrap it in a tmux session (or use the AgentOcean web terminal) so you can detach and reattach without interrupting the run:

# Start a persistent session
tmux new -s code
claude

# Detach with Ctrl-b then d — the agent keeps running.
# Reattach later from any device:
tmux attach -t code

Keep your keys safe

Both tools are BYOK (Bring Your Own Key). Set the keys as environment variables so every shell session picks them up — add them to ~/.bashrc, or keep them in a .env file and source it. Never commit keys to a repo:

# Append to ~/.bashrc so keys load on every login
echo 'export ANTHROPIC_API_KEY="sk-ant-..."' >> ~/.bashrc
echo 'export OPENAI_API_KEY="sk-..."'        >> ~/.bashrc
source ~/.bashrc

# Or keep them in a .env (and add .env to .gitignore)
# ANTHROPIC_API_KEY=sk-ant-...
# OPENAI_API_KEY=sk-...

Your keys live on your own server and are billed against your Anthropic or OpenAI account — they never pass through AgentOcean.

Skip the setup

On AgentOcean you can pre-install Claude Code or Codex when you order a Cloud VPS — Node.js and the CLI are ready the moment your box boots. Just add your API key and start coding.

Related