DigitalOcean

Run a Python Bot 24/7 on a DigitalOcean VPS

How to deploy a persistent Python bot on a Linux VPS using a dedicated user, virtual environment, systemd, logs and a firewall.

DigitalOcean droplet agent failure message
Hands-on screenshot: 24/7 hosting still has operational failure modes that need monitoring.

How to deploy a persistent Python bot on a Linux VPS using a dedicated user, virtual environment, systemd, logs and a firewall.

Updated 2026-09-06DigitalOceanPractical guide2 min read

In plain English

This guide assumes a long-running service on a Linux VPS. Your home PC can be off, but the VPS still needs proper service management, updates, logs and secrets.

VPSsystemdSSHlogs

Keep the server boring

For a small bot, reliability usually improves when the server has fewer moving parts. A common stack is Ubuntu, one dedicated application directory, one Python virtual environment, systemd, and either SQLite or a managed database.

Suggested layout

/opt/bot/
  app/
    main.py
    broker.py
    strategy.py
  data/
    bot.db
  logs/
  venv/
  .env

Install into a virtual environment

python3 -m venv /opt/bot/venv
/opt/bot/venv/bin/pip install -r /opt/bot/app/requirements.txt

A virtual environment avoids mixing bot dependencies with the operating system's Python packages.

Run under systemd

Do not rely on an SSH terminal staying open. systemd can start the process at boot, restart it after a crash, and put stdout/stderr into the journal.

[Unit]
Description=Bot service
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=bot
WorkingDirectory=/opt/bot/app
EnvironmentFile=/opt/bot/.env
ExecStart=/opt/bot/venv/bin/python /opt/bot/app/main.py
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

Operations commands

sudo systemctl daemon-reload
sudo systemctl enable --now bot.service
sudo systemctl status bot.service
journalctl -u bot.service -n 100 --no-pager
journalctl -u bot.service -f
Practical lesson: “the service is active” is not the same as “the bot is healthy.” Add a heartbeat or last-success timestamp so you can detect a process that is running but stuck.

Firewall

If the bot does not need a public web server, do not expose one. If it does, put HTTPS/reverse proxy or Cloudflare in front, and bind internal services to localhost or a private interface when possible.

Before you rely on this in production

  • Service starts after reboot.
  • Firewall exposes only required ports.
  • Secrets have restricted permissions.
  • Logs and disk usage are monitored.
A real VPS problem

Hosting failures are part of bot reliability

DigitalOcean console showing droplet agent is not running
DigitalOcean

Web console could not reach the droplet

The droplet agent stopped responding. A 24/7 bot needs more than correct Python code: you also need alternative access, service logs and restart procedures.

Terminal showing an Unauthorized unable to authenticate response
Authentication

Remote work can fail before the bot even starts

Authentication failures need a controlled diagnosis of credentials, sessions and target environment rather than blind retries.