EQVPS

How to run an AI agent on a VPS (Python, venv, systemd)

A copy-paste how-to for running an AI agent on a VPS: set up Python and a virtualenv, keep API keys in an env file, and wrap the agent in a systemd service so it restarts on crash and survives reboots.

An AI agent that only runs while your laptop is open is a script. To make it run itself — reconnecting, retrying, surviving reboots — put it on a VPS under systemd. This is the minimal, copy-paste how-to. For the why and the longer form (uptime, sizing, the MCP angle), see run an AI agent 24/7 and the VPS for AI agents overview.

1. Python and a virtualenv

apt update && apt install -y python3-venv python3-pip git
git clone https://github.com/you/your-agent.git /opt/agent
cd /opt/agent
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt

2. Keep the API key in an env file

Never hard-code keys. Put them in a file only root can read:

cat >/opt/agent/.env <<'EOF'
ANTHROPIC_API_KEY=sk-ant-...
EOF
chmod 600 /opt/agent/.env

3. Wrap it in a systemd service

# /etc/systemd/system/agent.service
[Unit]
Description=AI Agent
After=network.target

[Service]
WorkingDirectory=/opt/agent
ExecStart=/opt/agent/.venv/bin/python main.py
EnvironmentFile=/opt/agent/.env
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now agent
journalctl -u agent -f      # watch it run

Restart=always is the whole point: a crash at 3 a.m. restarts instead of leaving the agent dead until morning. (More on the pattern in create a systemd service.)

4. Watch for crash loops

If the agent fails instantly on start, Restart=always retries forever. RestartSec=5 spaces attempts out; read journalctl -u agent to fix the underlying error (usually a missing env var or dependency).

Sizing and the honest bits

EQVPS also exposes an MCP server, so an agent can even provision its own box. Root in about a minute, no KYC, pay in crypto.

FAQ

What do I need to run an AI agent on a VPS?

Python with a virtualenv for the agent's dependencies, your model API key in an environment file, and a systemd service so it restarts on crash and starts on boot. If the agent calls a hosted model (the common case) that's all — no GPU. The steps are below; you get root in about a minute.

Where do I put the API key?

In an EnvironmentFile (chmod 600), never in the unit file or committed to git. systemd loads it into the process environment at start. That keeps a leaked unit or repo from leaking your key.

How do I keep the agent running after I disconnect?

Wrap it in a systemd service with Restart=always. Unlike running it in a terminal or with nohup, systemd restarts it on crash, starts it on boot, and captures logs to journalctl. That's the difference between a script and an agent that runs itself.

Do I need a GPU?

Not if the agent calls a hosted model over an API — that's CPU-only orchestration work, comfortable on a small box. You only need a GPU to run a model locally, which we don't offer; for small local models on CPU see the Ollama guide.

Do you ask for ID or a card?

No. Email to sign up, pay in USDC or USDT — no documents, no card. Root in about a minute.

Comments

No comments yet. Be the first.

Leave a comment

Comments are moderated before they appear.