−25%

on annual Windows plans, until 31 Oct. See plans

EQVPS

Securing a self-hosted AI agent on a VPS

Sep 26, 2026 · 4 min read · EQVPS Team

A classic web app does what its code says. An AI agent does what its code says plus whatever the text it reads convinces it to do. Give it a shell, an API key and a budget, point it at the open internet, and you've built something new: a process that can be socially engineered. The fix isn't paranoia, it's the old sysadmin habit of least privilege — applied to a very talkative program.

Know the actual threats

Everything below either makes these less likely or makes them cheaper when they happen.

1. Give the agent its own box and its own user

Run agents that execute code or browse the web on a separate VPS — not next to your production database. On that box, never as root:

adduser --disabled-password --gecos "" agent
mkdir -p /home/agent/work && chown agent:agent /home/agent/work

No sudo, no SSH keys to other servers, no access to anything it doesn't need.

2. Sandbox it with systemd

systemd can fence a process in without containers. The agent can read the system but write only to its working directory:

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

[Service]
User=agent
WorkingDirectory=/home/agent/work
EnvironmentFile=/home/agent/.agent.env
ExecStart=/home/agent/venv/bin/python run_agent.py
Restart=on-failure
NoNewPrivileges=yes
ProtectSystem=strict
ProtectHome=read-only
ReadWritePaths=/home/agent/work
PrivateTmp=yes
PrivateDevices=yes
MemoryMax=2G

[Install]
WantedBy=multi-user.target

ProtectSystem=strict makes the whole filesystem read-only except ReadWritePaths. MemoryMax stops one runaway task from taking the server down. Check the result with systemd-analyze security agent — it scores the unit and lists what's still open.

3. Treat keys like they will leak

4. Cap what it can buy

If the agent can spend money, the limit must live outside the agent. On EQVPS an agent orders and renews servers from the account's prepaid balance through the MCP server or REST API — so the balance is a hard ceiling. Top it up with the amount you're prepared to lose, not with your whole budget. Give the agent its own account if it doesn't need to see your other servers.

5. Put a human in front of irreversible actions

Deleting data, sending money, pushing to main, emailing customers: route these through a confirmation step — a Telegram message with an approve button is enough. Read-only tools can run freely; write tools earn trust slowly.

6. Narrow the exits (if you can live with it)

An outbound allowlist makes secret exfiltration much harder:

ufw default deny outgoing
ufw allow out 53          # DNS
ufw allow out 443/tcp     # HTTPS APIs
ufw allow out 80/tcp      # package mirrors
ufw default deny incoming && ufw allow 22/tcp && ufw enable

Honestly, this is the step most people drop: browsing agents need arbitrary HTTPS, and then an allowlist by port adds little. It's worth it for agents that only call a fixed set of APIs.

7. Keep logs and a way back

Log every tool call with its arguments. Take a snapshot before you let an agent loose on something new — Managed Backups give you daily restore points plus on-demand snapshots — so a bad afternoon costs a restore, not a rebuild.

The honest bottom line

None of this makes an agent safe to trust blindly. It makes it cheap to be wrong: a compromised agent on its own box, under its own user, with a capped balance and scoped keys, can do only small, recoverable damage. That's the realistic goal. Start with the basics in securing a new VPS, then add the agent-specific layers above.

FAQ

What is the biggest risk of running an AI agent on a server?

Prompt injection: the agent reads text it didn't write — a web page, an email, an issue comment — and that text tells it to do something you never asked for, like printing its environment variables or running a command. Everything else in this guide is about limiting the damage when that happens.

Should the agent run as root?

Never. Give it its own unprivileged user with no sudo, and restrict what it can write with systemd sandboxing. If it's tricked into running a destructive command, it can only damage its own working directory.

How do I stop an agent from overspending?

Use hard limits that live outside the agent: spending caps on your model provider keys, and a prepaid balance for anything it can buy. On EQVPS an agent spends from the account balance, so the balance itself is the ceiling — top it up with what you're willing to lose, not more.

Can I block prompt injection completely?

No — there's no reliable filter for it today. What works is reducing the blast radius: least-privilege tools, human confirmation for destructive or paid actions, no secrets in the agent's context, and logs you can review.

Is a separate VPS worth it for an agent?

Yes, if the agent runs code or browses the web. A small dedicated box keeps it away from your databases, other projects and credentials. If it gets compromised you rebuild one server, not your whole setup.

← Back to blogSee plans & pricing →

Comments

No comments yet. Be the first.

Leave a comment

Comments are moderated before they appear.