How to Deploy OpenCode Web on a VPS
Updated Nov 2026
verified on Ubuntu 26.04 · Nov 2026Run the OpenCode AI coding agent's web UI on a VPS with Docker Compose, password login behind Caddy HTTPS, and backups of sessions you can restore.
- A VPS (see Server sizing below)
- A fresh Ubuntu 26.04 server with root/sudo SSH access
- A domain or subdomain you can point at the server
- An API key for a model provider, or a model endpoint of your own
What you are building
OpenCode is an MIT-licensed coding agent. opencode web
serves it in a browser, so your sessions live on the server and you can reach
them from any machine. The models are not included: you connect a provider.
For a different agent, see OpenHands.
An agent with a web UI is a remote shell. Whoever logs in can run commands
inside the container and read everything mounted into it, including your
provider keys. OpenCode serves without a password unless
OPENCODE_SERVER_PASSWORD is set. This guide sets it before the first start,
mounts only a workspace directory, and does not mount the Docker socket.
Server sizing
On the catalog's test box the server measured about 182 MB of memory idle and about 320 MB of disk. Builds and tests the agent runs in your workspace need their own memory on top, and the stock image may not contain your toolchain.
Prepare the server
Update the system and install the tools this guide uses:
sudo apt-get update && sudo apt-get -y upgrade
sudo apt-get install -y curl openssl ufw dnsutils
If you're logged in as root, create a non-root sudo user and continue as that user:
adduser deploy
usermod -aG sudo deploy
Open SSH and the two ports the reverse proxy needs:
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw --force enable
A published Docker port goes around ufw, so the Compose file below decides
what is reachable: OpenCode gets no public port of its own.
Paid link — we earn a commission if you shop through it.
Install Docker
If Docker isn't on the server yet, the convenience script installs Docker Engine and the Compose plugin (the Docker and Compose on Ubuntu guide covers the details):
command -v docker >/dev/null || curl -fsSL https://get.docker.com | sudo sh
sudo docker compose version
Configure the stack
Replace code.example.com with your hostname:
mkdir -p ~/opencode/workspace ~/opencode/data ~/opencode/config && cd ~/opencode
DOMAIN=code.example.com
[ -f .env ] || ( umask 077
{ echo "DOMAIN=$DOMAIN"
echo "OPENCODE_SERVER_PASSWORD=$(openssl rand -hex 24)"
} > .env )
data holds sessions and provider credentials, config holds your settings and
workspace holds the code the agent works on. The :? makes Compose refuse to
start if the password is empty.
cd ~/opencode
cat > docker-compose.yml <<'EOF'
services:
opencode:
image: ghcr.io/anomalyco/opencode:1.19.5
restart: unless-stopped
command: ["web", "--hostname", "0.0.0.0", "--port", "4096"]
working_dir: /workspace
environment:
OPENCODE_SERVER_PASSWORD: ${OPENCODE_SERVER_PASSWORD:?set it in .env}
volumes:
- ./workspace:/workspace
- ./data:/root/.local/share/opencode
- ./config:/root/.config/opencode
caddy:
image: caddy:2
restart: unless-stopped
ports: ["80:80", "443:443"]
environment:
DOMAIN: ${DOMAIN}
volumes: ["./Caddyfile:/etc/caddy/Caddyfile:ro", "caddy_data:/data"]
depends_on: [opencode]
volumes:
caddy_data:
EOF
cat > Caddyfile <<'EOF'
{$DOMAIN} {
reverse_proxy opencode:4096
}
EOF
( umask 077; . ./.env; echo "user = \"opencode:$OPENCODE_SERVER_PASSWORD\"" > curlrc )
sudo docker compose up -d
HTTPS and the domain
Create an A record for your hostname pointing at the server's public IP and confirm it resolves before Caddy asks for a certificate:
dig +short code.example.com
Caddy requests the certificate once the name resolves and renews it on its own
(see Automatic HTTPS with Caddy). Check that the password is enforced: 200 signed in, 401 anonymous.
. ~/opencode/.env
code=000
for i in $(seq 1 30); do
code=$(curl -s -K ~/opencode/curlrc -o /dev/null -w '%{http_code}' "https://$DOMAIN/session")
[ "$code" = 200 ] && break
sleep 5
done
anon=$(curl -s -o /dev/null -w '%{http_code}' "https://$DOMAIN/session")
echo "signed in $code, anonymous $anon"; [ "$code" = 200 ] && [ "$anon" = 401 ]
First login
Open https://code.example.com. The browser asks for a user name and password:
the user is opencode, the password is OPENCODE_SERVER_PASSWORD in
~/opencode/.env. Then connect a provider in the UI, and set a spending limit
with that provider. To rotate the login password, edit .env and curlrc and
run sudo docker compose up -d.
Create an empty session over the API, so the backup has something to prove. This needs no model:
cd ~/opencode
. ./.env
curl -sf -K curlrc -X POST "https://$DOMAIN/session" -H 'Content-Type: application/json' \
-d '{"title":"restore me"}'; echo
echo "restore me" > hello.txt && sudo cp hello.txt workspace/hello.txt
Backups
Sessions are stored in a database under data, so stop the server for a
consistent copy:
cd ~/opencode
sudo docker compose stop opencode
( umask 077; sudo tar czf - data config workspace .env curlrc docker-compose.yml Caddyfile > ~/opencode-backup.tar.gz )
sudo docker compose start opencode
ls -lh ~/opencode-backup.tar.gz
Copy it off the server to encrypted storage: it contains your provider keys.
Restore
This replaces the current sessions, settings and workspace. On a new server,
unpack into ~/opencode before starting.
The block checks the archive first and stops at the first error.
(
set -e
cd ~/opencode
tar tzf ~/opencode-backup.tar.gz >/dev/null
sudo docker compose stop opencode
sudo rm -rf data config workspace
sudo tar xzf ~/opencode-backup.tar.gz
sudo docker compose up -d
. ./.env
for i in $(seq 1 30); do curl -sf -K curlrc -o /tmp/s.json "https://$DOMAIN/session" && break; sleep 3; done
grep -q 'restore me' /tmp/s.json
grep -x 'restore me' workspace/hello.txt
)
Upgrades
OpenCode releases often, and a 2.x line is already out. This guide was tested on
1.19.5 only, so treat a move to 2.x as a major upgrade. Read the
release notes, back up, change
the tag (this guide pins 1.19.5), then:
cd ~/opencode
sudo docker compose pull
sudo docker compose up -d
sudo docker compose ps
Troubleshooting
cd ~/opencode && sudo docker compose logs --tail=100 opencode caddy
Next steps
Compare providers in Best VPS for self-hosting.
Next steps
Common questions
How long does it take to follow "How to Deploy OpenCode Web on a VPS"?
We estimate about 20 minutes of hands-on time for "How to Deploy OpenCode Web on a VPS"; this is an editorial estimate, not a measurement.
Was the "How to Deploy OpenCode Web on a VPS" guide tested?
The "How to Deploy OpenCode Web on a VPS" guide was verified end-to-end on Ubuntu 26.04 (Nov 2026).