Why run an AI agent on a VPS?
An AI agent such as Claude Code, OpenAI's Codex CLI or your own bot sends its prompts to a model provider's API, then runs commands and edits files on the machine it lives on. A VPS keeps that machine online 24/7 when your laptop sleeps, keeps the agent away from your personal files, and gives it a fixed IP and NVMe storage. The model runs on the provider's servers, so a CPU VPS is enough.
What a CPU VPS can and cannot run
A virtual private server for AI agents doesn't need a GPU when the model runs elsewhere. Claude Code calls Anthropic, Codex CLI calls OpenAI, and agents built on their SDKs do the same. For visual AI workflows, see n8n self-hosting on a VPS.
| Workload | On our VPS | Why |
|---|---|---|
| Claude Code, Codex CLI and other coding agents | Runs well | The model runs at the provider; the VPS runs commands and tests. |
| Your own agents, bots and n8n workflows on a model API | Runs well | Small processes that must stay online. |
| Agents that drive a headless browser | Runs, with more RAM | Each browser needs its own memory. |
| Small local models on CPU | Runs, slowly | Without a GPU, answers come far slower than from a hosted API. |
| Large local LLMs, fine-tuning or training | Not a fit | Our VPS plans have no GPU. |
Every RapidServer VPS is a KVM server with dedicated vCPU, NVMe and full root, but no GPU.
Secure Linux setup
- Deploy Ubuntu 24.04 LTS or Debian 12. Anthropic's Claude Code setup page lists Ubuntu 20.04+ and Debian 10+ with 4 GB of RAM or more. Add your SSH key in the client area first: every new VPS boots with it installed and password login disabled.
- Create an admin user with sudo and close root login, as in our developer setup steps.
- Give the agent its own user, without sudo, so a bad command can reach only that user's files. Keep it out of the
dockergroup too, which is close to root.
sudo adduser --disabled-password agent
Switch to it with sudo -iu agent. An agent that only calls APIs needs no open port except SSH: run sudo ufw allow OpenSSH, then sudo ufw enable. Add fail2ban and unattended-upgrades for security updates.
Install Python, Node.js and the agent
sudo apt update && sudo apt install -y git tmux python3-venv
Python comes with Ubuntu and Debian; give each project its own environment with python3 -m venv .venv. For Node.js, install a current LTS release from nodejs.org or with nvm, as distribution packages can lag behind.
Claude Code
Claude Code runs in the terminal, so it works over SSH. As the agent user, run Anthropic's native installer:
curl -fsSL https://claude.ai/install.sh | bash
Then run claude in a project folder. You need a paid Claude plan or a Claude Console account. With no browser on the server, press c to copy the login link, open it on your laptop and paste the code back if asked, or set ANTHROPIC_API_KEY (Anthropic's login guide).
Codex CLI and other agents
OpenAI's Codex CLI is a coding agent that runs locally, which here means on the server. Install it with npm install -g @openai/codex or OpenAI's install script, then run codex. On a headless server, sign in with codex login --device-auth (a beta, switched on in ChatGPT's security settings) or with an API key (OpenAI's sign-in guide). Other agents follow the same pattern: one CLI or script, one key, one Linux user.
Keep it running: tmux or systemd
Anything started in a plain SSH session stops when you disconnect.
tmux for interactive agents such as Claude Code and Codex:
tmux new -s agent
Start the agent, detach with Ctrl+B then D, and log out; it keeps working. Later, run tmux attach -t agent from your laptop or phone.
systemd for agents that run on their own, such as a bot or a worker loop, so they start at boot and restart after a crash. Create /etc/systemd/system/my-agent.service; under [Service], the key lines are:
| Line | What it does |
|---|---|
User=agent | Runs it as the agent user, not root |
WorkingDirectory=/home/agent/my-agent | Starts in the project folder |
EnvironmentFile=/home/agent/.config/my-agent.env | Loads the API keys |
ExecStart=/home/agent/my-agent/.venv/bin/python main.py | Starts your agent |
Restart=always | Restarts it after a crash |
Add WantedBy=multi-user.target under [Install] so it starts at boot, then run:
sudo systemctl daemon-reload && sudo systemctl enable --now my-agent
Follow its logs with journalctl -u my-agent -f. For scheduled jobs, cron or a systemd timer can call Claude Code's non-interactive mode, claude -p, which refuses actions that need approval unless you allow those tools with --allowedTools. Authenticate it with a Console API key, or a token from claude setup-token on a Claude plan.
Keeping API keys safe
- One locked file. Keep keys in an environment file such as
~/.config/my-agent.env, owned by the agent user, withchmod 600. In tmux, load it withset -a; . ~/.config/my-agent.env; set +a. - Never in git. Add env files to
.gitignore. Git keeps history, so a key committed once stays readable after you delete it. - One key per project, with a limit. Create separate keys in the Anthropic or OpenAI console and set spending limits there, so a leak or a runaway loop has a ceiling. If a key may have leaked, revoke it and make a new one.
- Login files count too.
~/.claude/.credentials.jsonand~/.codex/auth.jsonhold tokens; OpenAI says its file is plain text, so keep it private and never commit it.
Sizing by workload
| Workload | Starting plan | Per month |
|---|---|---|
| One coding agent, or a small bot on a model API | Stardust: 2 vCPU, 4 GB RAM, 20 GB NVMe | ₹581 |
| An agent across several repositories and build caches | New Moon: 2 vCPU, 4 GB RAM, 40 GB NVMe | ₹674 |
| Several agents at once, Docker, a database or a headless browser | Full Moon: 4 vCPU, 8 GB RAM, 160 GB NVMe | ₹1,723 |
| A shared agent server for a team, with CI | Eclipse: 8 vCPU, 16 GB RAM, 320 GB NVMe | ₹3,445 |
Every plan meets Claude Code's 4 GB RAM minimum. Builds, tests, Docker, browsers and parallel agents are what grow the server. Watch free -m for a week, then resize from the client area with the difference prorated. Prices exclude 18% GST. For websites, see how much VPS you need.
KVM with dedicated vCPU, NVMe and full root in Mumbai or Delhi NCR, ready a few minutes after payment, from ₹581/mo.
See VPS hosting plansMumbai or Delhi?
Mumbai (BOM1) and Delhi NCR (DEL1) cost the same. An agent talks mostly to its model provider and to you, so pick the city nearest you, or nearest the servers the agent works on. Mumbai suits western and southern India and international traffic; Delhi NCR suits Delhi, Noida, Gurugram and the north. The two are about 22 ms apart, and our team moves a VPS between them for free. See latency from each city.
Backups and your own git remote
Every RapidServer VPS gets daily backups kept for 7 days, plus snapshots on demand. Take a snapshot before a big agent refactor or a package upgrade, and roll back if it goes wrong.
Also push to your own git remote, such as a private GitHub or GitLab repository. Have the agent work on a branch and push after each task, using a deploy key limited to that repository. Backups protect the server; the remote protects the work and lets you review every change.
What it costs
- The server: a fixed RapidServer price from ₹581/mo plus 18% GST, billed monthly in rupees with a GST invoice. It costs the same whether the agent is busy or idle, with no yearly lock-in.
- The model: your Claude or ChatGPT plan, or API usage, billed separately by Anthropic, OpenAI or whichever provider you use. RapidServer isn't affiliated with them and doesn't sell their plans or API credits.
Questions
Can I run Claude Code on a VPS?+
Can I use a VPS for OpenAI Codex?+
Do I need a GPU VPS to run AI agents?+
Can I run a local LLM on a CPU VPS?+
How much RAM does a VPS for AI agents need?+
Is it safe to keep API keys on a VPS?+
chmod 600, never in git, a separate key per project with a spending limit, and the agent running without sudo. Revoke any key you think has leaked.