Back to Blog
by Davis Stanko · April 19, 2026 · 3 min read

Self-Hosting a Battlesnake

In this guide you will run your Battlesnake on a computer in your own home. You will serve it with Gunicorn, put Caddy in front of it, publish it to the internet with Tailscale Funnel, and make it update itself from Git.

What You Need

  • A computer that can stay on all day. An old desktop works.
  • Debian installed on it. Other Linux systems work too, but this guide uses Debian commands.
  • Your snake's code in a Git repository.
  • A free Tailscale account.

If you do not have a snake yet, build one first. My guide on writing a Battlesnake in Python covers that part.

Step 1: Get the Code on the Machine

Log into the machine and install the tools:

apt update
apt install git python3 python3-pip python3-venv

Clone your snake and install what it needs:

git clone https://github.com/yourname/yoursnake.git
cd yoursnake
python3 -m venv venv
./venv/bin/pip install flask gunicorn

Your snake needs a file the server can run. Mine is main.py, and the app inside it is called app. Change the names below if yours differ.

Step 2: Run the Snake with Gunicorn

The server Python ships with is for testing. Gunicorn is a real server. Run it like this:

./venv/bin/gunicorn --workers 1 --threads 8 --bind 127.0.0.1:8000 main:app

The bind address matters. 127.0.0.1 means the snake only answers requests from this machine. Nothing on the internet can reach it yet. The proxy in step 4 handles the public side.

One worker is enough. A move request is short. The search is the slow part, not the server.

Test it from a second terminal:

curl http://127.0.0.1:8000/

You should get a small JSON reply with your snake's details. That means the snake is up.

Step 3: Make It a Service

You want the snake to start on boot and restart if it crashes. systemd does both.

Create /etc/systemd/system/battlesnake.service:

[Unit]
Description=Battlesnake
After=network.target

[Service]
WorkingDirectory=/home/yourname/yoursnake
ExecStart=/home/yourname/yoursnake/venv/bin/gunicorn --workers 1 --threads 8 --bind 127.0.0.1:8000 main:app
Restart=always

[Install]
WantedBy=multi-user.target

Enable and start it:

systemctl enable --now battlesnake

Step 4: Put Caddy in Front

Caddy is a web server that works well as a front door. It takes public requests and passes them to Gunicorn.

Install it:

apt install caddy

Add this block to /etc/caddy/Caddyfile:

:9010 {
	reverse_proxy 127.0.0.1:8000
}

Reload Caddy:

systemctl reload caddy

The snake now answers on port 9010 of the machine. It is still not public. Your home router blocks outside requests, and that is fine. The next step goes around it.

Step 5: Publish It with Tailscale Funnel

Port forwarding is the old way to do this. It needs a static IP or a dynamic DNS setup, and it opens a port on your router. Tailscale Funnel is simpler. It gives the machine a public HTTPS address and carries the traffic for you.

Install Tailscale and log in:

curl -fsSL https://tailscale.com/install.sh | sh
tailscale up

Turn on Funnel for the Caddy port:

tailscale funnel 9010

Tailscale shows you an address like https://your-machine.your-tailnet.ts.net. Open it in a browser. You should see the same JSON reply as before. Anyone on the internet can now reach your snake, over HTTPS, with no changes to your router.

Step 6: Point Battlesnake at It

Go to your snake's settings on the Battlesnake site. Set the URL to your Funnel address. Save, then run a test game.

Watch the machine while the game runs:

journalctl -u battlesnake -f

You will see one request per turn. If the moves come back and the snake plays, the setup is done.

Step 7: Make It Update Itself

You will change your snake often. Pushing code and then logging in to update the server gets old fast. A timer can do it for you.

Create a small script at /home/yourname/deploy.sh:

#!/bin/bash
cd /home/yourname/yoursnake
git pull
systemctl restart battlesnake

Make it executable:

chmod +x /home/yourname/deploy.sh

Create /etc/systemd/system/battlesnake-deploy.service:

[Unit]
Description=Update Battlesnake from Git

[Service]
Type=oneshot
ExecStart=/home/yourname/deploy.sh

Create /etc/systemd/system/battlesnake-deploy.timer:

[Unit]
Description=Run the Battlesnake update every five minutes

[Timer]
OnBootSec=1min
OnUnitActiveSec=5min

[Install]
WantedBy=timers.target

Enable the timer:

systemctl enable --now battlesnake-deploy.timer

Now push a change to your repo. Within five minutes, the server picks it up on its own. Most runs change nothing, and the restart is harmless. Your snake holds no state between turns. Each request carries the whole board.

Step 8: Mind the Clock

The game gives you 500 ms per move. That budget includes the trip across the internet and back.

I give my search 400 ms and leave the rest for travel. If your snake thinks until the last millisecond at home, it will time out in real games. Test with real games, not just local ones. Local replies always look fast.

Closing Thoughts

The whole setup costs nothing per month and lives on a computer I already owned. It has no cold starts and no request limits, and the search can use as much of the machine as I let it. A rented server still works fine, and my static site guide covers that path. But for a snake, the computer in the corner is enough.