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
- API-backed agent (model runs at your provider): light — a Small ($8) or the AI-Agent plan ($10, 4 GB) is plenty. No GPU needed.
- Local model: different, heavier setup — small quantized models on CPU via Ollama; big ones need a GPU we don't offer.
- Containerised instead? Docker's
--restart unless-stoppedplays the same role — see docker-compose for AI agents.
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.
Comments
No comments yet. Be the first.