How to Deploy an AI Agent: Cloud, VPS, and Serverless Options
Building an AI agent is step one. Deploying it so it runs 24/7 is step two. This guide covers all your options — from free serverless to dedicated VPS — with cost comparisons and setup guides.
Builder of AI agents, crypto trading bots, and open-source automation tools. Sharing practical guides on how to build, deploy, and profit from AI and DeFi technology.
Why Deployment Matters for AI Agents
Your laptop can run an agent during testing, but for a trading bot or monitoring agent that needs to operate 24/7, you need a reliable hosting solution.
Key requirements for AI agent deployments:
- Uptime — 99.9%+ for anything handling money
- Low latency — Critical for trading bots
- Persistent storage — For agent memory and logs
- Cost efficiency — AI API calls add up
Option 1: VPS (Virtual Private Server)
Best for: Trading bots, high-frequency agents, anything requiring speed
Recommended providers:
- Hetzner (Germany/US) — Best price/performance. 2 vCPU, 4GB RAM from €4.15/month
- DigitalOcean — Easy to use, great docs. 1 vCPU, 1GB RAM from $6/month
- Vultr — High performance. Metal servers available
- AWS EC2 — Enterprise reliability, higher cost
Setup Guide (Ubuntu 22.04)
# 1. Update system
sudo apt update && sudo apt upgrade -y
# 2. Install Node.js
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
# 3. Install PM2 for process management
npm install -g pm2
# 4. Clone your agent
git clone https://github.com/yourusername/your-agent
cd your-agent
npm install
# 5. Set environment variables
echo "OPENAI_API_KEY=sk-..." > .env
# 6. Start with PM2
pm2 start dist/index.js --name "my-agent"
pm2 save
pm2 startup # Auto-restart on server reboot
Monitoring with PM2
pm2 status # Check running processes
pm2 logs my-agent # View real-time logs
pm2 monit # CPU/memory dashboard
Option 2: Serverless (AWS Lambda, Vercel, Cloudflare Workers)
Best for: Event-driven agents, lightweight tasks, low traffic
Serverless is great for agents triggered by webhooks, scheduled tasks (cron), or API calls.
AWS Lambda Example
// handler.ts
import { runAgent } from './agent'
export const handler = async (event: AWSLambda.ScheduledEvent) => {
console.log('Running scheduled agent task...')
const result = await runAgent('Check crypto prices and send alert if BTC drops 5%')
return { statusCode: 200, body: JSON.stringify({ result }) }
}
Deploy with AWS CDK:
import { Function, Runtime } from 'aws-cdk-lib/aws-lambda'
import { Schedule, Rule } from 'aws-cdk-lib/aws-events'
const agent = new Function(this, 'AgentFunction', {
runtime: Runtime.NODEJS_20_X,
handler: 'handler.handler',
timeout: Duration.minutes(5),
environment: { OPENAI_API_KEY: process.env.OPENAI_API_KEY! }
})
// Run every 5 minutes
new Rule(this, 'AgentSchedule', {
schedule: Schedule.rate(Duration.minutes(5)),
targets: [new LambdaFunction(agent)]
})
Cloudflare Workers (Edge)
Ideal for lightweight agents that need global low latency:
export default {
async scheduled(event: ScheduledEvent, env: Env): Promise<void> {
// Runs on cron schedule
const result = await runLightweightAgent(env.OPENAI_API_KEY)
await env.KV.put('last_result', JSON.stringify(result))
}
}
Option 3: Docker + Self-Hosted
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY dist ./dist
CMD ["node", "dist/index.js"]
docker build -t my-agent .
docker run -d \
--name my-agent \
--restart unless-stopped \
-e OPENAI_API_KEY=sk-... \
my-agent
Option 4: Railway / Render / Fly.io
Zero-infrastructure platforms — just push code and they handle the rest.
Railway:
npm install -g railway
railway login
railway init
railway up
Render: Connect GitHub repo, set environment variables, deploy. From $7/month.
Choosing the Right Option
| Use Case | Recommended | Cost | |----------|-------------|------| | Trading/arbitrage bot | Hetzner VPS (near exchange) | $5–20/month | | Scheduled monitoring agent | AWS Lambda or Vercel Cron | $0–5/month | | Web-facing AI app | Vercel + serverless | $0–20/month | | High-throughput agent | DigitalOcean Droplet | $10–40/month |
Security Best Practices
- Never store API keys in code — Use environment variables
- Use secrets managers — AWS Secrets Manager, Doppler
- Set spending limits on OpenAI and exchange accounts
- Monitor for anomalies — Set alerts for unusual spend or behavior
- Use read-only API keys where possible
- Firewall your VPS — Only open ports you need
Get Pre-Configured Deployment Templates
Our GitHub repos include Docker configs, PM2 configs, and deployment scripts for all major platforms. Check the Tools page to get started.
Related Articles
Agentic AI: The Next Evolution Beyond ChatGPT (Complete 2025 Guide)
9 min read
AI AgentsHow to Give Your AI Agent Long-Term Memory
6 min read
AI AgentsAutonomous vs Semi-Autonomous AI Agents: When to Choose Each
4 min read
AI AgentsOpenAI Assistants API vs Custom Agents: Full Comparison
4 min read