Deploy a Python AI Agent to DigitalOcean: Step-by-Step Guide

Building an AI agent on your laptop is the fun part. Then you close the lid, and your agent goes to sleep with it. To make it actually useful — answering webhooks, running on a schedule, serving an API your other apps can call — it needs to live on a server that never sleeps.

This guide walks you through deploying a Python AI agent to DigitalOcean, from a blank account to a running service with HTTPS. We'll cover both deployment paths (a hands-on Droplet and the managed App Platform), so you can pick the one that fits how much you want to babysit a server.

As of June 2026, this is one of the cheapest reliable ways to host a small agent: a $6/month box will happily run a FastAPI service that calls Claude or GPT, because the expensive compute happens on the model provider's side, not yours.

Disclosure: fundesk is a DigitalOcean affiliate. Some DigitalOcean links below are affiliate links — if you sign up through them we may earn a commission, at no extra cost to you. We only recommend DigitalOcean here because it's a genuinely good fit for this job.

What does it mean to "deploy" an AI agent?

Deploying an AI agent means moving your code from your local machine to a server that runs it continuously, reachable over the internet, surviving reboots and crashes. For a Python agent that calls a hosted LLM, "deployment" is mostly standard web-app deployment — there's nothing AI-specific about the infrastructure until you start running models locally.

Key takeaways:

  • 🖥️ A cheap CPU server is enough if your agent calls a hosted LLM API (Claude, GPT). You don't need a GPU.
  • ⚖️ Two paths on DigitalOcean: a Droplet (a raw Linux VM you control) or App Platform (managed, push-to-deploy from GitHub).
  • 🔁 systemd keeps it alive — your app restarts on crash and on reboot, independent of your SSH session.
  • 🔒 Nginx + Certbot gives you a clean HTTPS endpoint on your own domain in about five minutes.
  • 💸 The LLM API is your real cost, not the $6/month server.

📋 What You'll Need

  • A DigitalOcean account — sign up at digitalocean.com. New accounts often get free trial credit.
  • A working Python agent — any FastAPI/Flask app, or use the minimal example below.
  • An LLM API key — from Anthropic, OpenAI, or whichever provider your agent uses.
  • Basic terminal comfort — you'll SSH into a server and run a handful of commands.
  • An SSH key pair — for secure, password-free login (we'll generate one if you don't have it).
  • A domain name (optional) — needed only if you want HTTPS on a real hostname instead of a bare IP.

A minimal agent to deploy

So the steps are concrete, here's a tiny FastAPI agent. It exposes one /chat endpoint that forwards a message to an LLM and returns the reply. Save it as app.py:

import os
from fastapi import FastAPI
from pydantic import BaseModel
from anthropic import Anthropic

app = FastAPI()
client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])

class ChatRequest(BaseModel):
    message: str

@app.get("/health")
def health():
    return {"status": "ok"}

@app.post("/chat")
def chat(req: ChatRequest):
    response = client.messages.create(
        model="claude-sonnet-4-6",
        max_tokens=1024,
        messages=[{"role": "user", "content": req.message}],
    )
    return {"reply": response.content[0].text}

With a requirements.txt:

fastapi
uvicorn[standard]
anthropic
pydantic

Test it locally first — deploying broken code to a fresh server just adds variables you don't want:

export ANTHROPIC_API_KEY=sk-ant-...
pip install -r requirements.txt
uvicorn app:app --reload
# visit http://localhost:8000/health

Once /health returns {"status": "ok"} and /chat answers, push this to a GitHub repo. Both deployment paths below pull from there.


Droplet vs App Platform: which should you pick?

DigitalOcean gives you two ways to run this. They solve the same problem with opposite philosophies.

Droplet App Platform
What it is A raw Linux VM you fully control A managed platform that builds & runs your repo
Setup effort Higher — you install everything Lower — connect GitHub, click deploy
Maintenance You patch the OS, manage the process DigitalOcean handles it
Control Total — system packages, workers, cron, GPUs Limited to what the platform supports
Background jobs Easy (systemd, cron) Needs a separate "worker" component
Local models Possible (pick a big/GPU Droplet) Not really
Starting price ~$6/mo (as of June 2026) ~$5/mo basic service (free for static sites)
Best for Control, tinkering, cheapest compute Shipping fast with no server upkeep

Rule of thumb: if you just want your agent live and never want to think about a server again, use App Platform. If you want control — background workers, custom packages, a local model later, or simply to learn how a server actually works — use a Droplet. We'll do the Droplet path in full (it teaches you more), then the App Platform shortcut.

Tip: Prices and Droplet specs change. Check the live DigitalOcean pricing page before you create anything — the numbers here are accurate as of June 2026.

Path A: Deploy to a Droplet (full control)

Step 1 — Create the Droplet

In the DigitalOcean dashboard, click Create → Droplets and choose:

  • Image: Ubuntu 24.04 LTS
  • Plan: Basic → Regular → the $6/mo option (1 GB RAM / 1 vCPU / 25 GB SSD). Plenty for an API-calling agent.
  • Region: pick the one closest to your users (lower latency).
  • Authentication: SSH key (not password — it's both safer and less hassle).

If you don't have an SSH key yet, generate one locally and paste the public half into DigitalOcean:

ssh-keygen -t ed25519 -C "[email protected]"
cat ~/.ssh/id_ed25519.pub   # paste this into the DigitalOcean "New SSH Key" box

Create the Droplet and copy its public IP address.

Step 2 — Log in and prep the box

SSH in as root, then install Python tooling:

ssh root@YOUR_DROPLET_IP

apt update && apt upgrade -y
apt install -y python3-venv python3-pip nginx git

Don't run your app as root. Create a dedicated user:

adduser --disabled-password --gecos "" appuser

Step 3 — Pull your code and install dependencies

su - appuser
git clone https://github.com/YOUR_USERNAME/YOUR_REPO.git app
cd app
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Step 4 — Run it as a systemd service

This is the step that turns "a script I ran once" into "a service that stays up." systemd restarts your app if it crashes and starts it again after a reboot. Exit back to root (exit) and create the service file:

nano /etc/systemd/system/agent.service
[Unit]
Description=AI Agent (FastAPI)
After=network.target

[Service]
User=appuser
WorkingDirectory=/home/appuser/app
Environment="ANTHROPIC_API_KEY=sk-ant-your-real-key"
ExecStart=/home/appuser/app/venv/bin/uvicorn app:app --host 127.0.0.1 --port 8000
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

Note --host 127.0.0.1 — the app only listens locally, and Nginx will be the only thing exposed to the internet. Start and enable it:

systemctl daemon-reload
systemctl enable --now agent
systemctl status agent      # should say "active (running)"
Warning: Putting your API key directly in the service file is fine to start, but anyone with root can read it. For anything real, load secrets from an EnvironmentFile (e.g. /etc/agent.env) with chmod 600, or use DigitalOcean's secret management. Never commit keys to your repo.

Step 5 — Put Nginx in front

Your app is running on 127.0.0.1:8000 but the world can't reach it. Nginx forwards public traffic to it:

nano /etc/nginx/sites-available/agent
server {
    listen 80;
    server_name YOUR_DOMAIN_OR_IP;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

Enable it and reload:

ln -s /etc/nginx/sites-available/agent /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx

Now http://YOUR_DROPLET_IP/health works from anywhere.

Step 6 — Add HTTPS (if you have a domain)

Point an A record for your domain at the Droplet's IP, then let Certbot handle the certificate:

apt install -y certbot python3-certbot-nginx
certbot --nginx -d youragent.example.com

Certbot fetches a free Let's Encrypt certificate, rewrites your Nginx config to use it, and sets up auto-renewal. You now have https://youragent.example.com — done.

Step 7 — Lock down the firewall

ufw allow OpenSSH
ufw allow 'Nginx Full'
ufw enable

Only SSH and web traffic get through. Your app port (8000) stays invisible to the outside world.


Path B: Deploy to App Platform (managed)

If steps 4–7 above made you wish a robot would just do it, that robot is App Platform.

  1. In the dashboard, click Create → Apps.
  2. Connect your GitHub repo and pick the branch.
  3. App Platform auto-detects Python. Set the run command: uvicorn app:app --host 0.0.0.0 --port 8080 (App Platform expects port 8080).
  4. Add your ANTHROPIC_API_KEY under Environment Variables, marked as encrypted.
  5. Choose the Basic plan (~$5/mo) and click Deploy.

That's it. No SSH, no Nginx, no systemd. HTTPS, builds, and restarts are handled for you, and every push to your branch triggers a redeploy. The trade-off is less control — background workers need a separate component, and you can't drop down to the OS.

Tip: Start on App Platform to get live today. If you later hit its limits — a long-running background worker, a system dependency it won't install, or you want to run a local model — graduate to a Droplet. The app code doesn't change; only where it runs does.

What does this actually cost?

The server is the cheap part. Here's a realistic monthly picture for a small agent (as of June 2026):

Item Cost Notes
Droplet (1 GB) ~$6/mo Runs a FastAPI agent comfortably
App Platform (basic) ~$5/mo Managed alternative to the Droplet
Domain name ~$1/mo ~$12/year, optional
HTTPS certificate $0 Let's Encrypt via Certbot
LLM API usage $ varies Usually your biggest line item

The lesson: don't over-optimize the $6 server. If your agent gets real traffic, the Claude or GPT API bill will dwarf the hosting cost. Size the server for your concurrency, not your ego — a 1 GB box handles far more API-relaying traffic than people expect, because it spends most of its time waiting on the LLM, not computing.


Troubleshooting common deployment problems

systemctl status agent shows "failed."
Check the logs: journalctl -u agent -n 50. Usual suspects: a missing environment variable, a wrong path in WorkingDirectory, or a dependency that didn't install. Fix, then systemctl restart agent.

502 Bad Gateway from Nginx.
Nginx is up but your app isn't answering on 127.0.0.1:8000. Confirm the service is running (systemctl status agent) and that the port in your systemd ExecStart matches the proxy_pass port in Nginx.

Certbot fails to issue a certificate.
Almost always DNS. Your domain's A record must point at the Droplet IP and have propagated. Check with dig youragent.example.com and wait if it's still resolving to the old value.

App Platform build fails.
Read the build log in the dashboard. Most failures are a missing requirements.txt or the wrong run command/port. App Platform expects your app to bind 0.0.0.0:8080, not 127.0.0.1:8000.

The agent works locally but 500s on the server.
Nine times out of ten, the API key isn't set in the server environment. Confirm it's present in the systemd Environment= line (Droplet) or the encrypted env vars (App Platform).


Frequently Asked Questions

How much does it cost to host a Python AI agent on DigitalOcean?
A basic Droplet starts around $6/month (1 GB RAM, 1 vCPU) as of June 2026, which comfortably runs a small FastAPI agent that calls an external LLM API. App Platform's basic web service tier starts around $5/month. Your real cost driver is usually the LLM API itself, not the server.

Should I use a DigitalOcean Droplet or App Platform for an AI agent?
Use App Platform if you want a managed, push-to-deploy setup from GitHub with zero server maintenance. Use a Droplet if you need full control — background workers, custom system packages, GPUs, or local models. Droplets are cheaper per unit of compute; App Platform saves you time.

Do I need a GPU to deploy an AI agent?
No, not if your agent calls a hosted LLM API like Claude or GPT. The heavy compute runs on the provider's servers, so a cheap CPU Droplet is enough. You only need a GPU if you're running a model locally on the server.

How do I keep my Python app running after I close the SSH session?
Run it as a systemd service. systemd starts your app on boot, restarts it if it crashes, and keeps it running independently of your SSH session. This guide includes a ready-to-use service file.

How do I add HTTPS to a DigitalOcean Droplet?
Put Nginx in front of your app as a reverse proxy, point a domain at the Droplet's IP, then run Certbot to get a free Let's Encrypt certificate. Certbot auto-configures Nginx and renews the certificate automatically.


What's Next

New to shipping AI systems for real? Start with The Rise of the AI Engineer for the bigger picture, then come back and put your agent online.

Want hands-on AI engineering tutorials like this in your inbox? Subscribe to the fundesk newsletter for new guides as they drop.


Share Your Thoughts

Read More

AI Automation for Small Business: Where to Start in 2026
AI Coding Agents Compared: Cursor vs Copilot vs Claude Code vs Windsurf in 2026
AI Coding Agents and Security Risks: What You Need to Know
AI Pair Programming: The Productivity Guide for 2026
AI SRE Agents Explained: Platform Comparison and Pilot Guide for 2026
AI UI Testing with Vision Agents (2026): Catch Visual Bugs Before They Ship
Browse all AI-Assisted Engineering articles

Stay Ahead

Only insights that save you time or money. No fluff, ever.

Stay Ahead

Only insights that save you time or money. No fluff.