There’s a moment every developer has with an AI coding agent. You’re on your laptop at a café, you ask it to refactor an old module, and then… your fan starts screaming, your battery starts melting, and you realize the agent has been spinning for ten minutes while your whole machine crawls. I love these tools, but running them on the machine you actually work on is asking for pain.
When you run AI coding agents on a VPS, all of that goes away. The agent lives on a server with dedicated resources, it keeps working when you close your laptop, and you can hand it a task at midnight and wake up to a pull request. In this guide I’ll walk you through why it works so well, the specs that actually matter, which agents to pick, a step-by-step setup, the security rules you absolutely shouldn’t skip, and what it really costs.
Table of Contents
Why Run AI Coding Agents on a VPS Instead of Your Laptop?
AI coding agents — tools like Claude Code, Aider, and OpenHands — aren’t like a chatbot in a browser tab. They read your whole codebase, run tests, execute shell commands, install dependencies, and sometimes spin up services. That behavior has real consequences for the machine they run on:
- Resource hunger. Agents with large context windows and background processes can eat gigabytes of RAM and hold CPU for long stretches. On a laptop, that means heat, fan noise, and everything else slowing down.
- Long-running tasks. A good agent session might run for an hour or more — test suites, linters, builds. Your laptop sleeps, throttles, or loses Wi-Fi. A VPS doesn’t.
- Consistent environment. Your laptop has Python 3.11, the agent wants 3.12, your other project needs 3.9 — sound familiar? On a VPS you build one clean, reproducible environment per project and never fight your daily driver again.
- Always-on access. Connect from your phone, your tablet, or a borrowed laptop. The agent keeps working while you’re commuting, sleeping, or on a different machine entirely.
- Isolation. This is the big one. Agents run shell commands. You do not want an AI agent with shell access anywhere near your personal files, your SSH keys, or your banking tabs. A VPS is a cheap, disposable sandbox.
If you’re new to the concept, our primer on what VPS hosting is explains the basics — but the short version is: a virtual private server is your own slice of a powerful machine in a datacenter, and it’s the ideal home for an AI agent.
The Specs That Actually Matter (And the Ones That Don’t)
Here’s the first thing to understand: most AI coding agents don’t do the heavy AI lifting on your server. The big language model runs in the cloud (Anthropic, OpenAI, whoever powers your agent), and your VPS is doing the “hands” work — reading files, running git, executing tests, managing processes. That changes the spec calculus completely.
The spec that matters most is RAM, then CPU cores, then disk speed. A GPU is almost never necessary — unless you’re also running a local model on the same box (see our guide to running AI models on a VPS if that’s your plan). Here’s a realistic breakdown:
| Use case | RAM | CPU | Disk | Approx. cost |
|---|---|---|---|---|
| Light — one agent, small repos, occasional sessions | 4 GB | 2 vCPU | 60 GB SSD | $6–12/mo |
| Standard — daily driver, medium repos, parallel agents | 8 GB | 4 vCPU | 120 GB NVMe | $15–25/mo |
| Heavy — big monorepos, test suites, multiple agents + services | 16–32 GB | 6–8 vCPU | 200+ GB NVMe | $30–60/mo |

Honest opinion: start at 8 GB RAM / 4 vCPU. It’s the sweet spot where agents feel snappy, you can run two sessions at once, and you’re not paying for capacity you’ll never touch. You can always resize a VPS in minutes — every provider lets you scale up without rebuilding. Our breakdown of cheap VPS options that don’t sacrifice performance is a good place to hunt for that tier.
One more spec note: location matters more than people think. Every keystroke round-trips between you and the agent, so pick a datacenter near you. A 200ms difference in latency is the difference between an agent that feels alive and one that feels laggy. We covered the full decision in our VPS server location guide.
Pick Your Agent: Claude Code vs Aider vs OpenHands
The agent landscape moves fast, but three options cover nearly everyone’s needs right now. Here’s the honest comparison:
| Agent | Best for | How it runs | Model cost model |
|---|---|---|---|
| Claude Code | Terminal-first developers who want the smartest agent available | CLI on your server, you connect over SSH | API usage or subscription |
| Aider | Pair-programming style, works with many models, great git integration | CLI, pairs nicely with tmux for persistence | Bring your own API key (pay per use) |
| OpenHands | A full agent “workspace” with web UI, sandboxed execution | Docker container with browser-based interface | Bring your own API key |
My take: if you’re already comfortable in a terminal, start with Claude Code or Aider — they’re the fastest to get running and the easiest to reason about. OpenHands is genuinely impressive, but it’s a heavier lift (Docker, more RAM) and shines when you want a self-contained agent environment with a GUI. There’s no wrong answer here; you can run all three on the same VPS.
A quick word on model costs, because nobody warns you about this: the VPS is the cheap part. API usage for a heavy agent session can run anywhere from a few cents to a few dollars, and an enthusiastic weekend of agent-driven refactoring can surprise you. Set a spending alert on your API account on day one. Seriously.
Step-by-Step: Setting Up Your VPS for AI Coding Agents
This walkthrough assumes a fresh Ubuntu 22.04/24.04 server. If you haven’t hardened a fresh box yet, run through our new VPS setup checklist first — it takes ten minutes and saves you from the classic mistakes.
1. Create a dedicated agent user
Never run agents as root. Create a locked-down user whose damage radius is limited to its own home directory:
sudo adduser agent
sudo usermod -aG sudo agent # only if the agent needs to install packages
su - agent
2. Install the essentials
sudo apt update && sudo apt upgrade -y
sudo apt install -y git tmux htop curl build-essential python3-pip nodejs npm
git config --global user.name "agent"
git config --global user.email "agent@yourdomain.com"
tmux is non-negotiable. It keeps your agent session alive when SSH drops. Start every agent inside a tmux session and you’ll never lose work to a flaky connection again.
3. Install your agent
For Claude Code (npm-based):
npm install -g @anthropic-ai/claude-code
tmux new -s claude
claude
For Aider (pip-based):
pip install aider-chat
tmux new -s aider
aider --model claude-3-7-sonnet-20250219
For OpenHands (Docker):
docker pull docker.all-hands.dev/all-hands-ai/runtime:0.28-nikolaik
docker run -it --rm --pull=always \
-e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.28-nikolaik \
-e LOG_ALL_EVENTS=true \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ~/.openhands:/.openhands \
-p 3000:3000 \
--add-host host.docker.internal:host-gateway \
--name openhands-app \
docker.all-hands.dev/all-hands-ai/openhands:0.28
Then open http://your-server-ip:3000 in a browser (lock this down — more on that in the security section). The Aider documentation is genuinely excellent if you want to go deeper on configuration.
4. Clone your repos and set up SSH keys
Generate a deploy key on the VPS (never copy your personal SSH private key onto a server):
ssh-keygen -t ed25519 -C "vps-agent" -f ~/.ssh/id_ed25519 -N ""
cat ~/.ssh/id_ed25519.pub # add this as a deploy key on GitHub/GitLab
5. Connect and go
SSH in, attach to your tmux session (tmux attach -t claude), and start giving the agent tasks. From here on, your laptop is just a window into a machine that never sleeps.

Lock It Down: Security Rules You Shouldn’t Skip
This is the section most tutorials wave away, and it’s the most important one in this whole article. An AI coding agent executes shell commands on your server. That means a confused agent, a prompt-injection attack hidden in a repo you cloned, or a compromised dependency could do real damage. Treat your agent server like a workshop full of power tools, not a locked office.
- Run agents as a non-root user with access limited to project directories. Never root.
- Firewall everything. Only SSH (port 22, ideally moved or key-only) and any specific service ports should be open. Use UFW:
sudo ufw allow OpenSSH && sudo ufw enable. - SSH keys only, no passwords. Disable password auth in
/etc/ssh/sshd_config. This single change blocks the vast majority of automated attacks. - Sandbox risky work. For untrusted repos or experimental agents, run inside Docker with limited mounts — the agent gets a container, not your host.
- Separate deploy keys per project with read-only access where possible. One key per repo means a compromised key can’t touch your other projects.
- Review before you merge. The agent writes code; you (or CI) review it. Never let an agent push directly to your main branch.
- Keep API keys in environment variables, never in the repo, never in chat logs. A
.envfile withchmod 600is the minimum.
Our VPS security guide covers the full hardening routine — firewall rules, fail2ban, automatic updates — and I’d genuinely run through it before giving any agent shell access.
What It Really Costs to Run AI Coding Agents on a VPS
Let’s be honest about the full bill, because the VPS is only half the story:
- The VPS itself: $6–25/month for most people (see the spec table above). Annual billing usually shaves 10–20% off.
- Model/API usage: $5–50/month depending on how hard you push the agent. This is the variable part — a casual week might cost $3, an intense refactoring sprint might cost $30.
- Subscriptions (optional): some agents offer flat-rate plans that can be cheaper than pay-per-use if you’re a heavy user. Do the math on your actual usage after a month.
So realistically, $15–60/month all-in for a serious setup. Compare that to the “free” alternative: your $2,000 laptop wheezing through builds while you can’t use it for anything else. For anyone who codes daily, the VPS pays for itself in the first week — not in dollars, but in a machine that stays usable while the agent grinds away in the background.
Pro Tips: Getting More Out of Your Agent Server
- One tmux session per project. Name them clearly (
tmux new -s project-api) and you can context-switch between agents instantly. - Give the agent a project briefing file. A short
AGENT.mdin the repo root — architecture, conventions, what not to touch — dramatically improves output quality. It’s the highest-ROI five minutes you’ll spend. - Schedule it. A cron job that pulls the latest main, runs the test suite, and has the agent fix failures overnight is genuinely life-changing. Wake up to green builds.
- Use mosh instead of SSH for flaky connections — it roams across networks without dropping, perfect for agent sessions from a phone.
- Snapshot before big experiments. Most VPS providers offer one-click snapshots. Take one before letting the agent loose on a major refactor; rolling back takes seconds.
If you’re picking a provider specifically with agents in mind, our guide to the best VPS for AI agents compares the options that handle these workloads well.
FAQ
Do I need a GPU to run AI coding agents on a VPS?
No. The language model runs in the provider’s cloud; your VPS handles file operations, git, tests, and tooling — all CPU/RAM work. You only need a GPU if you’re also running local models on the same server.
How much RAM do AI coding agents need?
8 GB is the comfortable starting point for daily use. 4 GB works for light, occasional sessions; 16 GB+ makes sense for large monorepos or running multiple agents in parallel.
Is it safe to give an AI agent shell access?
It’s safe enough if you follow the rules: non-root user, firewall, SSH keys only, sandbox untrusted work in Docker, and always review code before merging. Never give an agent root, and never point one at a repo you don’t trust without sandboxing.
Can I run multiple coding agents on one VPS?
Yes — that’s one of the best reasons to do this. Give each agent its own tmux session and project directory. Just make sure you have enough RAM (roughly 4 GB per active agent as a rule of thumb).
Will the agent keep working when I close my laptop?
Yes, as long as the agent runs inside tmux (or a similar session manager) on the VPS. Closing your laptop only closes your window into the session — the work continues on the server.
Your 24/7 Coding Partner
Running AI coding agents on a VPS is one of those changes that feels small and turns out to be huge. Your laptop stays fast and quiet. Your agent works through the night. Your environments stay clean and reproducible. And the whole thing costs less than a streaming subscription or two.
Start with an 8 GB box, install one agent inside tmux, lock down SSH, and give it a real task tonight. By tomorrow morning you’ll wonder why you ever ran agents on your daily driver. Happy coding.


