Self-Host OpenHands AI Agent & Zero-Trust Homelab with Tailscale
Published 2026-11-14Category: Guides
Complete guide to deploying OpenHands AI coding agent on Contabo VPS via Docker and securing homelab access with Tailscale Grants, MagicDNS, and subnet routing.
Table of contents
- 1.Introduction & Industry Context
- 2.Side-by-Side Parameter & Key-Point Overview
- 3.Deep-Dive Breakdown & Operational Details
- 3.1.Production-Grade Docker Deployment of OpenHands on VPS & LLM Integration
- 3.2.Tailscale Homelab: From Device Admission to Grants Fine-Grained Permission Model
- 4.Scenario-Based Selection & Pitfall Checklist
- 5.Quick FAQ
- 5.1.OpenHands sandbox docker build fails with “Cannot connect to the Docker daemon”, how to troubleshoot?
- 5.2.Tailscale Grants policy applied but device still cannot reach target port, common gotchas?
- 5.3.How to make OpenHands Web UI accessible only via Tailscale without exposing any public IP?
- 6.Sources & References

Self-Host OpenHands AI Agent & Zero-Trust Homelab with Tailscale
Introduction & Industry Context
As large language model (LLM) capabilities have exploded, AI coding assistants have evolved from simple code completion into autonomous agents that can plan, write, test, and deploy code. OpenHands (formerly OpenDevin) stands as the flagship open-source project in this space, letting developers run an AI coding agent on fully controlled infrastructure and completely avoid the data-compliance risk of uploading proprietary codebases to public clouds. At the same time, distributed teams and individual developers increasingly need secure, anytime-anywhere access to homelab and private-cloud resources. Traditional VPN solutions fall short on NAT traversal, device management, and fine-grained permission control. Tailscale’s WireGuard-based zero-trust architecture, combined with its next-generation Grants access-control model, is becoming the standardized connective tissue between VPS cloud resources and local heterogeneous devices.
This deep-dive integrates two core hands-on scenarios: first, a production-grade OpenHands deployment on a Contabo VPS covering Docker orchestration, LLM provider integration, HTTPS termination, and API authentication hardening; second, Noted.lol’s battle-tested Tailscale homelab access-control advanced guide, from device admission to tag-based Grants policy authoring. The article targets full-stack engineers, DevOps practitioners, and advanced homelab enthusiasts with basic Linux ops skills who want to self-host AI development infrastructure and build a secure remote-access system. Through side-by-side parameter tables, deep-dive breakdowns, and scenario-specific checklists, it bridges the gap from “it runs” to “production-ready” before the end of 2026.
Side-by-Side Parameter & Key-Point Overview
| Dimension | OpenHands Self-Host (Contabo VPS) | Tailscale Homelab Access Control |
|---|---|---|
| Core Components | Docker Engine, ghcr.io/all-hands-ai/openhands:latest, reverse proxy, LLM API endpoint |
Tailscale client, Admin Console (Tailnet), ACL/Grants policy, MagicDNS |
| Key Prerequisites | VPS with public IP (recommend 4 vCPU / 8 GB+), domain + DNS control, valid SSL cert, LLM API key (OpenAI/Anthropic/local-compatible endpoint) | Tailscale account, devices joined to Tailnet, admin access to Admin Console |
| Deployment Complexity | Medium-high: Docker Compose orchestration, env var injection, reverse proxy config, WebSocket support, persistent volume management | Low-to-medium: mainly web-console policy syntax, no client changes |
| Security Hardening Focus | Enforce HTTPS, set APP_API_KEY to protect Web UI, run container non-root, limit host port exposure, regular image updates |
Enable device approval, deprecate legacy ACL in favor of Grants, least-privilege by tag/user, audit Machines list regularly |
| Typical Resource Usage | Idle ~500 MB RAM / 0.5 vCPU; active coding peaks 4-8 GB RAM / 2-4 vCPU (depends on workspace size & LLM context) | Client footprint tiny (<50 MB RAM); control-plane traffic minimal, data plane direct P2P |
| Hidden Limits / Risks | 1. Depends on external LLM API availability & cost; 2. Sandbox execution env needs proper isolation to prevent privilege escalation; 3. Long-running requires disk I/O & log rotation monitoring | 1. Free-tier Tailnet device/user caps; 2. Grants syntax steep learning curve; 3. DERP relay latency affects high-interactivity scenarios |
| Applicability Boundary | Team collaborative dev, private codebase refactoring, automated test generation, legacy migration, teaching demo environments | Remote Proxmox/NAS admin, cross-region device interconnect, third-party contractor temp access, replace legacy site-to-site VPN |
Deep-Dive Breakdown & Operational Details
Production-Grade Docker Deployment of OpenHands on VPS & LLM Integration
Contabo’s official blog establishes the standardized path for self-hosting OpenHands on a VPS: pull the ghcr.io/all-hands-ai/openhands:latest image and run it via Docker, with the critical challenge being how to securely bridge external LLM capability with the internal sandbox execution environment.
Hardware baseline: at least 4 vCPU and 8 GB RAM (Contabo VPS M series or equivalent). OpenHands spins up a full dev environment inside the container (Node.js, Python, Git, etc.) and maintains independent workspace snapshots per conversation session; memory pressure grows linearly with context window. Storage: mount /home/user/.openhands to a host high-performance SSD volume (or dedicated NVMe mount point) to avoid container-layer write amplification causing IOPS bottlenecks. Also set --shm-size=2g shared-memory parameter to prevent browser automation components (Playwright/Chrome) from crashing due to insufficient /dev/shm.
LLM integration is the cost/capability watershed. OpenHands supports any OpenAI-compatible endpoint via env vars LLM_API_KEY, LLM_BASE_URL, LLM_MODEL. Production recommends a gateway pattern: deploy LiteLLM or OneAPI locally on the VPS as a proxy layer to centrally manage multi-vendor keys (OpenAI GPT-4o, Anthropic AI 3.5 Sonnet, local Ollama-served CodeLlama/DeepSeek-Coder), achieving failover, cost capping, and audit logging. Example compose snippet:
# docker-compose.yml fragment
services:
openhands:
image: ghcr.io/all-hands-ai/openhands:latest
environment:
- LLM_API_KEY=${GATEWAY_API_KEY}
- LLM_BASE_URL=https://llm-gateway.internal/v1
- LLM_MODEL=gpt-4o
- APP_API_KEY=${STRONG_RANDOM_KEY} # protects Web UI entry
- SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.18-nikolaik
volumes:
- ./data:/home/user/.openhands
- /var/run/docker.sock:/var/run/docker.sock # sandbox needs DinD
deploy:
resources:
limits:
memory: 8G
cpus: '4'
Note SANDBOX_RUNTIME_CONTAINER_IMAGE must strictly match the OpenHands version to avoid sandbox API incompatibilities that break command execution. Mounting /var/run/docker.sock grants the sandbox Docker-in-Docker (DinD) capability, a prerequisite for OpenHands to run docker build, docker compose up, etc., but also introduces container-escape risk; production should migrate to rootless Docker or gVisor/Kata Containers for sandbox hardening.
HTTPS & authentication are prerequisites for public exposure. The tutorial mandates TLS termination at the reverse-proxy layer (Nginx/Caddy/Traefik) with WebSocket support (proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade;) because OpenHands frontend/backend communication heavily relies on long-lived connections pushing terminal streams and code changes. Caddyfile example:
openhands.yourdomain.com {
reverse_proxy http://localhost:3000 {
header_up Host {host}
header_up X-Real-IP {remote}
header_up X-Forwarded-For {remote}
header_up X-Forwarded-Proto {scheme}
}
# automatic Let's Encrypt cert issuance
}
Combined with APP_API_KEY forcing all API requests to carry Authorization: Bearer <key> header, this effectively blocks unauthorized scanning and abuse. Post-deploy, watch docker logs -f openhands for “Server listening on port 3000” and “Sandbox runtime connected” dual green lights, then complete first login in browser and optionally link GitHub/GitLab OAuth to pull private repos.
Tailscale Homelab: From Device Admission to Grants Fine-Grained Permission Model
Noted.lol’s Part 5 systematically explains the evolution of Tailscale access control: the default fully-meshed Tailnet mode only suits early single-user few-device scenarios. Once collaborators, IoT devices, or cross-VPC peering enter the picture, a layered zero-trust defense becomes mandatory.
First line of defense: device approval. In Admin Console → Devices → Device management enable “Require approval for new devices”. Every new login device (including re-installs on same hardware) lands in “Pending” state; admin must explicitly approve in Machines page. This effectively prevents lateral movement after credential leakage, and combined with enforced MFA (Admin Console → Authentication → Mandate MFA) forms the identity admission baseline.
Core permission model has migrated from legacy ACL (IP/CIDR-based acls lists) to Grants (tag- and role-based declarative policy). Grants syntax aligns with infrastructure-as-code thinking. Example policy fragment:
{
"grants": [
{
"src": ["tag:developer"],
"dst": ["tag:app-server", "tag:db-proxy"],
"app": [{"proto": "tcp", "port": "22"}, {"proto": "tcp", "port": "3306"}]
},
{
"src": ["tag:contractor"],
"dst": ["tag:staging-web"],
"app": [{"proto": "tcp", "port": "443"}]
},
{
"src": ["tag:admin"],
"dst": ["tag:proxmox", "tag:nas-mgmt"],
"app": [{"proto": "tcp", "port": "8006"}, {"proto": "tcp", "port": "5000"}]
}
],
"tagOwners": {
"tag:developer": ["autogroup:member"],
"tag:contractor": ["[email protected]"],
"tag:admin": ["autogroup:admin"],
"tag:app-server": ["[email protected]"],
"tag:db-proxy": ["[email protected]"],
"tag:staging-web": ["autogroup:member"],
"tag:proxmox": ["[email protected]"],
"tag:nas-mgmt": ["[email protected]"]
}
}
Key design points: 1) src and dst reference tags not IPs; tagging a device auto-applies policy without editing rules; 2) tagOwners explicitly authorizes who may apply tags, preventing privilege escalation; 3) app field pins to port level, realizing “only 443 open, not 22/3306” least privilege. For high-risk ports like Proxmox management (8006) and NAS Web UI (5000/5001), restrict to tag:admin only and pair with Tailscale SSH (tailscale ssh user@host) to replace key-based login, auditing all session records.
MagicDNS & Subnet Router synergy further simplifies ops: enable MagicDNS in Admin Console → DNS; every Tailnet device automatically gets hostname.tailnet-name.ts.net records. Combine with Subnet Router (tailscale up --advertise-routes=192.168.10.0/24) to inject home LAN segments into Tailnet; remote devices reach home NAS, printers, cameras without route-table changes. Caveat: Subnet Router becomes a single point of failure; production should deploy dual-node HA (same --advertise-routes, Tailscale auto ECMP load-balances) and configure static routes on router pointing back to Tailnet CIDR (100.64.0.0/10) to prevent leakage from non-Tailscale devices.
Exit Node & access-control interaction is often overlooked: if a device advertises as Exit Node (--advertise-exit-node), others can route egress through it. Grants must explicitly allow app: [{"proto": "tcp", "port": "*"}] with dst containing tag:exit-node, otherwise devices can connect to the Exit Node but cannot forward traffic. Recommend tagging Exit Node as tag:exit-node and only authorizing tag:travel-device to use it, preventing internal servers from misrouting and leaking data.
Scenario-Based Selection & Pitfall Checklist
-
Solo dev / small team self-host AI coding assistant (budget-sensitive): Choose Contabo VPS L series (8C/16G/400 GB NVMe/32 TB traffic, ~€12.99/mo), deploy OpenHands + local Ollama running quantized DeepSeek-Coder-V2 (needs 16 GB+ VRAM or system RAM offload), LLM cost drops to zero. Pitfalls: must enable
APP_API_KEYand configure Caddy auto-renew certs; scheduledocker system prune -ato clean sandbox leftover images and avoid filling disk. -
Enterprise private codebase refactoring / compliance audit (data never leaves domain): Use self-hosted GPU servers (A100 40 GB ×2) running full-parameter models, OpenHands deployed on internal K8s cluster, exposed to authorized devs via Tailscale Subnet Router. Pitfalls: Grants for
tag:developeronly open OpenHands port (3000) and Git ports (22/9418), strictly forbid direct DB/object-storage ports; enable Tailscale SSH to record all sandbox ops in audit logs. -
Cross-region homelab interconnect & remote admin (NAS/Proxmox/Home Assistant): Core node runs Tailscale Subnet Router (x86 soft-router or spare Mini PC recommended), home segment
192.168.x.0/24advertised into Tailnet. Pitfalls: disable UPnP/NAT-PMP on router to avoid port conflicts; set MagicDNS search suffix to.home.arpato avoid public DNS clashes; regularlytailscale status --jsonmonitor DERP latency, spin up self-hosted DERP server if relay hops too high. -
Third-party contractor / outsourced temp access (least privilege, auditable, revocable): Create
tag:contractor,tagOwnersonly project manager can tag; Grants open only target service ports (e.g., 3000/8080/443), set device expiry (Admin Console → Machines → … → Set expiry); one-click revoke device auth when task ends. Pitfalls: disable “allow device to create Auth Key” to prevent unauthorized invites; require contractor to enable device-level MFA. -
Unified entry for Docker self-hosted service matrix (reverse proxy + zero trust): Traefik/Caddy listens on Tailnet IP (100.x.y.z) responding only to internal requests, paired with Tailscale HTTPS certs (
tailscale cert <domain>) for zero-cost internal TLS. Pitfalls: Docker network modehostormacvlanso containers get real Tailnet IP;docker.sockproxy containers (e.g., Portainer Agent) taggedtag:mgmtwith separate grants, never exposed to dev tags.
Quick FAQ
OpenHands sandbox docker build fails with “Cannot connect to the Docker daemon”, how to troubleshoot?
90% of the time this is due to missing or insufficient /var/run/docker.sock mount. Verify docker-compose.yml includes volumes: - /var/run/docker.sock:/var/run/docker.sock and host Docker daemon runs (systemctl status docker). If host uses rootless Docker, socket path is $XDG_RUNTIME_DIR/docker.sock; adjust mount accordingly. Advanced: docker exec -it openhands bash then docker version to test DinD connectivity; if permission denied, check container user (default user UID 1000) belongs to docker group, or inject GID via --group-add $(getent group docker | cut -d: -f3).
Tailscale Grants policy applied but device still cannot reach target port, common gotchas?
Three frequent misconfigurations: 1) Tag not effective: tagOwners authorized principal must match actual tagging actor (e.g., autogroup:member only lets device tag itself; admin needs autogroup:admin); run tailscale status --json and inspect Tags field. 2) Port/protocol typo: app must explicitly specify proto and port; ICMP needs separate {"proto": "icmp"}; wildcard only supports "port": "*" not protocol wildcard. 3) Policy conflict & priority: Grants is an allow-list with no explicit deny; if legacy ACL deny rules remain, wipe acls field entirely and keep only grants to avoid evaluation-order surprises.
How to make OpenHands Web UI accessible only via Tailscale without exposing any public IP?
Remove host port mapping from docker-compose.yml (delete ports: - "3000:3000"), so container listens only on internal container network. Deploy Caddy/Traefik reverse-proxy container in same Tailnet, configure reverse_proxy http://openhands:3000, obtain cert via tailscale cert openhands.tailnet-name.ts.net. In Grants, only allow tag:developer to access reverse-proxy container’s tag:reverse-proxy port 443. Architecture result: OpenHands fully hidden inside Tailnet, zero public attack surface, yet benefits from Tailscale native NAT traversal and DERP relay for low-latency global access.
Sources & References
- Contabo Blog: How to Self-Host OpenHands on a VPS: AI Coding Agent Setup (2026-11-09)
- Noted.lol: Tailscale Part 5: Securing Your Homelab with Access Controls (2026-11-11)
- 9to5Linux: XOrg Server 21.1.26 and Xwayland 24.1.15 Are Out to Patch More Security Issues (2026-11-11)
Spotted outdated pricing, stock, or expired coupons?See methodology & report an update →


