How to Self-Host an AI Agent on a VPS
Affiliate disclosure: This article contains affiliate links. If you click a link and make a purchase, we may earn a commission at no extra cost to you. Our editorial recommendations are never influenced by commissions — read our full disclosure policy.
Difficulty: Intermediate | Estimated time: 2-3 hours
---
Most people who ask about self-hosting an AI agent are really asking one of two different questions, and the answers point in opposite directions. This tutorial separates them, then walks the path if you decide to go ahead.
Step 1: Decide Whether You Should Self-Host At All
Self-hosting is not automatically cheaper, and it is never free — you pay in attention instead of subscription fees. Three questions settle it honestly.
Does your data have to stay somewhere specific? If you are handling client material, health or financial records, or anything under a data-residency obligation, this is a requirement rather than a preference, and it decides the question on its own.
Do you need the agent running when you are not? An agent that has to poll a mailbox, watch a queue or run overnight needs a machine that stays up. A laptop that sleeps is not that machine.
Are you willing to be the on-call engineer? This is the one people skip. A self-hosted agent that stops at 3am stays stopped until you notice. If that is unacceptable and you have no rota, buy the managed product and stop reading.
If none of the three applies, a hosted subscription is genuinely the better answer, and the rest of this guide is a hobby project rather than a business decision.
Step 2: Separate the Two Things You Are Buying
Blurring these is the single most common mistake, and it is expensive.
A server to run software on — the agent framework, its scheduler, its database, its web UI. This is ordinary hosting. The workload is modest and predictable, and a normal VPS handles it.
Somewhere to run a model — actual inference on open-weights models. This is a completely different shape of workload, it is the part that gets expensive, and it is where hardware assumptions matter.
You can absolutely run the first while calling a hosted API for the second, and for most people that is the right split: you control the agent, its memory, its logs and its credentials, and you rent the raw inference. Decide which of the two you are buying before you look at a single price.
Step 3: Pick the Server Tier Honestly
Match the machine to what it will actually do, not to what you hope to do in six months — you can move up later, and paying now for headroom you do not use is just a subscription with extra steps.
Contabo is one of the European hosts publishing this range openly, and its structure is a useful map of the tiers whatever you end up choosing: shared-resource VPS at the bottom, virtual dedicated servers where the cores are assigned to you rather than shared, and bare metal above that. It also publishes dedicated pages for the AI-specific end of this — hosted DeepSeek and Hermes AI VPS hosting — which is where the Step 2 distinction becomes concrete rather than theoretical.
We publish no prices or specifications here. Server pricing and configurations change far more often than a tutorial can honestly track, and the number you need is the one on the configuration page the day you buy.
Step 4: Choose a Managed Image or a Bare OS
A bare OS gives you total control and costs you an evening of setup. A pre-built image gives you a working stack in minutes and takes some of that control back.
The middle path most people end up on is a self-hosting platform — Dokploy is one, shipped as a pre-installed image on a Cloud VPS 6 — which gives you a dashboard for deploying and updating containerised apps without hand-writing deployment scripts. If your agent ships as a Docker container, this removes most of the work that makes people abandon self-hosting in week two.
If you specifically want to run an agent framework rather than assemble one, some hosts now publish pre-configured agent hosting as a product in its own right. Judge these the same way you would judge any managed offer: what exactly is pre-installed, who updates it, and can you get a shell on the box if you need one.
Step 5: Lock the Box Down Before Anything Else
Do this before the agent goes anywhere near it. A fresh server on a public IP starts getting probed within minutes, and an agent host is a worse thing to lose than a web server because of what it holds — API keys, mailbox access, and whatever it has been given permission to act on.
The minimum, in order: disable password SSH and use keys only; put a firewall in front of everything and open only the ports you actually need; enable unattended security updates; and never expose the agent's admin UI directly to the internet — put it behind a VPN or an authenticating proxy. If you would not leave the machine's front door unlocked, do not leave its web UI open because it "has a login page".
Step 6: Give the Agent Its Own Credentials
An autonomous agent will eventually do something you did not anticipate. The question is only how much damage that action can reach.
Create dedicated API keys and dedicated accounts for the agent, scoped to the narrowest permission set that lets it do its job, and never hand it credentials you also use yourself. Set spend limits on every paid API where the provider offers them. Keep the keys in environment variables or a secrets store, never in the repository — and if a key does leak, the fact that it was agent-specific is what turns a catastrophe into a rotation.
Step 7: Plan for the Day It Breaks
It will break, and usually while you are asleep.
Take backups of the agent's state and database, and — this is the part everyone skips — restore one once, deliberately, before you need to. A backup you have never restored is a hope, not a backup. Set the service to restart automatically on failure and on reboot. Add an uptime check that pings you when it stops. And write down, somewhere that is not the server itself, how to rebuild the whole thing from scratch; the day you need that document is the day the box is gone.
The Honest Summary
Self-hosting an AI agent is a genuinely good decision when data residency, always-on operation or cost at scale demands it, and a genuinely bad one when you are doing it to save a subscription you could afford. The infrastructure is the easy half. The half that decides whether you are still running it in six months is Step 7.
For choosing the agent software itself, see how to build an AI agent stack, and browse the full Agent Tutorials category.
Covered in this guide
Reviewed by NorwegianSpark Editorial — written with AI assistance and reviewed by the NorwegianSpark SA editorial team · Last updated: April 2026