You’ve been asked to stand up OpenHands — formerly OpenDevin — so engineers can hand off chores like “open a PR that bumps this dependency and updates the lockfile” to an autonomous agent. The Docker one-liner from the readme works, you give it your Anthropic key, the first run drafts a PR against a scratch branch, you hand it over. Six months later the agent has accumulated weeks of unreviewed diffs sitting in a workspace volume that nobody snapshots, the dev container runs as root and shares the Docker socket so an escaped container has the keys to the kingdom, the LLM key is in an env file with chmod 644, and the front-end is on plain HTTP because the readme example assumes localhost.
What’s happening
An OpenHands deployment that is actually production-ready needs more than docker run. Each agent session spawns a sandboxed runtime container that executes shell commands and edits files on behalf of the model — that container has to be resource-capped (CPU, memory, network egress), run as a non-root UID, and never share the host’s Docker socket. The workspace volume contains agent-modified code that is not yet upstream: it needs a backup window, a diff-review step before any git push, and a retention rule so abandoned sessions don’t pile up forever. The LLM provider key (Anthropic, OpenAI, or a local OpenAI-compatible endpoint) has to live in a 600-mode env file owned by root, not in the compose file. The web UI has to sit behind nginx with TLS and basic auth or OIDC, because anyone with the URL can spawn agent sessions that consume tokens and write code. None of these are individually critical — skip them and you’ve handed a model the keys to your dev environment with no audit trail.
How to verify
After install, the OpenHands web UI and the runtime container family on the host:
docker ps --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}'
# openhands-app ghcr.io/all-hands-ai/openhands Up
# openhands-runtime-... ghcr.io/all-hands-ai/runtime Up (spawned per session)
The app port must be on 127.0.0.1, never 0.0.0.0:
ss -lntp | grep -E ':(3000|443)\b'
# 127.0.0.1:3000 docker-proxy (openhands-app)
# 0.0.0.0:443 nginx
Round-trip a session-create call through nginx with basic auth:
curl -fsS -u ops:"${OH_BASIC_AUTH_PW}" https://openhands.example.com/api/options/config \
| jq .APP_MODE
# "saas" or "oss"
If the runtime container has /var/run/docker.sock mounted, the workspace volume isn’t backed up, or curl without basic auth returns 200, you’ve got a problem before the first agent run pushes to a real branch.
The fix
Save the script below as /root/setup-openhands-ubuntu22.sh, then run it. It runs the installer flow on a fresh Ubuntu 22.04 VM: base update, kernel tuning, file limits, UFW (SSH + HTTP + HTTPS only), SSH hardening, unattended-upgrades, Docker CE + compose plugin, NVIDIA container toolkit only if a GPU is detected (optional for OpenHands; useful if the LLM provider is local), a dedicated workspace volume at /var/lib/openhands/workspace, the official OpenHands compose stack with the app bound to 127.0.0.1:3000, runtime containers spawned with CPU/memory caps and a non-root UID, the LLM provider key written to /etc/openhands/openhands.env mode 600, nginx terminating TLS with basic auth on every path, Let’s Encrypt via certbot, and a poll loop that waits for the :3000 upstream before declaring success.
#!/usr/bin/env bash
set -euo pipefail
### Ubuntu 22.04 OpenHands clean VM installer
### Keeps root SSH key login enabled
### Disables SSH password login
### Enables automatic security updates
### Installs Docker, OpenHands, nginx, Let's Encrypt with basic auth
### No local backups; assumes VM-level backup. Workspace volume contains
### agent-modified code — review diffs before any git push upstream.
### Reboot remains manual
if [[ "$(id -u)" -ne 0 ]]; then
echo "Run as root."
exit 1
fi
: "${OH_DOMAIN:?Set OH_DOMAIN=openhands.example.com}"
: "${OH_EMAIL:?Set OH_EMAIL=ops@example.com for Let's Encrypt}"
: "${OH_LLM_PROVIDER:?Set OH_LLM_PROVIDER=anthropic|openai|local}"
: "${OH_LLM_API_KEY:?Set OH_LLM_API_KEY=<your provider key>}"
OH_LLM_MODEL="${OH_LLM_MODEL:-claude-3-7-sonnet-latest}"
OH_LLM_BASE_URL="${OH_LLM_BASE_URL:-}"
OH_VERSION="${OH_VERSION:-0.14}"
OH_BASIC_AUTH_USER="${OH_BASIC_AUTH_USER:-ops}"
OH_BASIC_AUTH_PW="${OH_BASIC_AUTH_PW:-$(openssl rand -base64 24 | tr -d '/+=' | head -c 24)}"
echo
echo "========================================"
echo "OpenHands Ubuntu 22.04 Setup"
echo "========================================"
echo
echo "==> Updating base OS"
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y upgrade
echo "==> Installing base packages"
apt-get -y install \
vim curl wget ca-certificates gnupg2 \
chrony fail2ban unattended-upgrades \
ufw lsof tcpdump dnsutils tar gzip \
iproute2 net-tools openssl jq apache2-utils \
pciutils software-properties-common
echo "==> Enabling time sync"
systemctl enable --now chrony
timedatectl set-ntp true
echo "==> Applying kernel/network tuning"
cat > /etc/sysctl.d/99-openhands.conf <<'SYSCTL'
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.core.somaxconn = 4096
net.core.netdev_max_backlog = 250000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.ip_local_port_range = 10240 65535
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0
kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
fs.file-max = 2097152
SYSCTL
modprobe tcp_bbr || true
echo tcp_bbr > /etc/modules-load.d/bbr.conf
sysctl --system
echo "==> Setting file limits"
cat > /etc/security/limits.d/99-openhands.conf <<'LIMITS'
* soft nofile 64000
* hard nofile 64000
root soft nofile 64000
root hard nofile 64000
LIMITS
echo "==> Configuring UFW"
ufw --force reset
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw --force enable
echo "==> Hardening SSH while keeping root SSH key login enabled"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%F-%H%M%S)
set_sshd_option() {
local key="$1"
local value="$2"
if grep -qE "^[#[:space:]]*${key}[[:space:]]+" /etc/ssh/sshd_config; then
sed -i "s|^[#[:space:]]*${key}[[:space:]].*|${key} ${value}|" /etc/ssh/sshd_config
else
echo "${key} ${value}" >> /etc/ssh/sshd_config
fi
}
set_sshd_option PermitRootLogin prohibit-password
set_sshd_option PasswordAuthentication no
set_sshd_option PubkeyAuthentication yes
set_sshd_option KbdInteractiveAuthentication no
set_sshd_option ChallengeResponseAuthentication no
set_sshd_option X11Forwarding no
set_sshd_option ClientAliveInterval 300
set_sshd_option ClientAliveCountMax 2
set_sshd_option MaxAuthTries 4
sshd -t
systemctl restart ssh
echo "==> Configuring fail2ban"
mkdir -p /etc/fail2ban/jail.d
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN
systemctl enable --now fail2ban
echo "==> Configuring unattended-upgrades for security"
cat > /etc/apt/apt.conf.d/20auto-upgrades <<'AUTOUPG'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
AUTOUPG
echo "==> Installing Docker CE"
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
| gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu jammy stable" \
> /etc/apt/sources.list.d/docker.list
apt-get update
apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl enable --now docker
echo "==> Detecting GPU"
GPU_PRESENT=0
if lspci | grep -i nvidia >/dev/null 2>&1; then
GPU_PRESENT=1
fi
if [[ "$GPU_PRESENT" -eq 1 ]]; then
echo "==> NVIDIA GPU detected — installing driver + nvidia-container-toolkit"
apt-get -y install linux-headers-$(uname -r)
wget -qO /tmp/cuda-keyring.deb \
https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
dpkg -i /tmp/cuda-keyring.deb
apt-get update
apt-get -y install cuda-toolkit-12-2 nvidia-driver-535
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey \
| gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list \
| sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' \
> /etc/apt/sources.list.d/nvidia-container-toolkit.list
apt-get update
apt-get -y install nvidia-container-toolkit
nvidia-ctk runtime configure --runtime=docker
systemctl restart docker
fi
echo "==> Creating openhands workspace"
mkdir -p /var/lib/openhands/workspace /var/lib/openhands/state /etc/openhands
chown -R 1000:1000 /var/lib/openhands/workspace /var/lib/openhands/state
chmod 750 /var/lib/openhands /var/lib/openhands/workspace /var/lib/openhands/state
echo "==> Writing OpenHands env file"
cat > /etc/openhands/openhands.env <<ENV
LLM_API_KEY=${OH_LLM_API_KEY}
LLM_MODEL=${OH_LLM_MODEL}
LLM_BASE_URL=${OH_LLM_BASE_URL}
SANDBOX_USER_ID=1000
SANDBOX_RUNTIME_CONTAINER_IMAGE=ghcr.io/all-hands-ai/runtime:${OH_VERSION}-nikolaik
WORKSPACE_MOUNT_PATH=/var/lib/openhands/workspace
ENV
chmod 600 /etc/openhands/openhands.env
chown root:root /etc/openhands/openhands.env
echo "==> Writing OpenHands docker-compose.yml"
cat > /etc/openhands/docker-compose.yml <<COMPOSE
services:
openhands:
image: ghcr.io/all-hands-ai/openhands:${OH_VERSION}
container_name: openhands-app
restart: unless-stopped
pull_policy: always
env_file:
- /etc/openhands/openhands.env
environment:
SANDBOX_RUNTIME_CONTAINER_IMAGE: \${SANDBOX_RUNTIME_CONTAINER_IMAGE}
SANDBOX_USER_ID: "1000"
WORKSPACE_MOUNT_PATH: /var/lib/openhands/workspace
LOG_ALL_EVENTS: "true"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /var/lib/openhands/state:/.openhands-state
- /var/lib/openhands/workspace:/opt/workspace_base
ports:
- "127.0.0.1:3000:3000"
extra_hosts:
- "host.docker.internal:host-gateway"
deploy:
resources:
limits:
cpus: "4"
memory: 8g
COMPOSE
echo "==> Starting OpenHands"
docker compose --env-file /etc/openhands/openhands.env -f /etc/openhands/docker-compose.yml up -d
echo "==> Waiting for OpenHands on 127.0.0.1:3000"
for i in {1..120}; do
if ss -lntp | grep -q '127.0.0.1:3000'; then
break
fi
sleep 2
done
if ! ss -lntp | grep -q '127.0.0.1:3000'; then
echo "OpenHands failed to listen on 127.0.0.1:3000"
docker logs openhands-app --tail=200 || true
exit 1
fi
echo "==> Installing nginx and certbot"
apt-get -y install nginx certbot python3-certbot-nginx
echo "==> Writing basic-auth credentials"
htpasswd -bc /etc/nginx/openhands.htpasswd "${OH_BASIC_AUTH_USER}" "${OH_BASIC_AUTH_PW}"
chmod 640 /etc/nginx/openhands.htpasswd
chown root:www-data /etc/nginx/openhands.htpasswd
cat > /etc/nginx/sites-available/openhands <<NGINX
upstream openhands_backend {
server 127.0.0.1:3000;
keepalive 32;
}
server {
listen 80;
listen [::]:80;
server_name ${OH_DOMAIN};
return 301 https://\$host\$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name ${OH_DOMAIN};
client_max_body_size 100M;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
proxy_connect_timeout 60s;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options SAMEORIGIN always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
auth_basic "OpenHands";
auth_basic_user_file /etc/nginx/openhands.htpasswd;
location / {
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_pass http://openhands_backend;
}
}
NGINX
ln -sf /etc/nginx/sites-available/openhands /etc/nginx/sites-enabled/openhands
rm -f /etc/nginx/sites-enabled/default
nginx -t
systemctl enable --now nginx
systemctl reload nginx
echo "==> Requesting Let's Encrypt certificate"
certbot --nginx --non-interactive --agree-tos \
-m "${OH_EMAIL}" -d "${OH_DOMAIN}" --redirect
systemctl enable --now certbot.timer
echo "==> Final package update"
apt-get -y upgrade
echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Kernel:"
uname -r
echo
if [[ "$GPU_PRESENT" -eq 1 ]]; then
echo "GPU:"
nvidia-smi -L || true
fi
echo
echo "Listeners:"
ss -lntp | grep -E ':(80|443|3000)\b' || true
echo
echo "Containers:"
docker ps --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}'
echo
echo "Services:"
systemctl is-active docker nginx fail2ban chrony || true
echo
echo "Web UI (basic auth):"
echo "https://${OH_DOMAIN}/"
echo "user: ${OH_BASIC_AUTH_USER}"
echo "password: ${OH_BASIC_AUTH_PW}"
echo
echo "LLM provider: ${OH_LLM_PROVIDER} model: ${OH_LLM_MODEL}"
echo "Provider key in /etc/openhands/openhands.env (mode 600). Move it to your secrets manager and remove the file from this host."
echo
echo "Workspace volume:"
echo "/var/lib/openhands/workspace — agent-modified code lives here."
echo "Back this up, and review diffs (git diff or a PR) before pushing any branch upstream."
Make it executable and run it:
chmod 700 /root/setup-openhands-ubuntu22.sh
OH_DOMAIN=openhands.example.com OH_EMAIL=ops@example.com \
OH_LLM_PROVIDER=anthropic \
OH_LLM_API_KEY=sk-ant-... \
OH_LLM_MODEL=claude-3-7-sonnet-latest \
/root/setup-openhands-ubuntu22.sh
First run pulls the OpenHands app image and the runtime image — expect a couple of minutes before :3000 comes up. Open https://openhands.example.com/, log in with the basic-auth credentials printed at the end, point the agent at a git repo cloned into /var/lib/openhands/workspace, and start a task. Critical operational note: that workspace volume contains agent-modified code that is not in your origin repository — git diff every session before you git push, and treat the workspace as a first-class backup target (it’s the equivalent of an unmerged feature branch nobody else can see). Rotate LLM_API_KEY out of /etc/openhands/openhands.env into your secrets manager; the on-disk copy is a bootstrap convenience.
Run the production agent on a Stack Harbor-managed environment with diff review, backup discipline, and Sev-1 escalation in place: Managed Cloud Ops.