#!/usr/bin/env bash # setup.sh: OpenSandbox server 1.2.1 with the Docker runtime on an exe.dev VM. # https://exe.dev/deploy/opensandbox # Safe to run again: it keeps the API key in ~/opensandbox/env. set -euo pipefail VERSION=1.2.1 VM=$(hostname) DIR=$HOME/opensandbox mkdir -p "$DIR" cd "$DIR" echo "== Docker: start at boot; no container-to-container traffic on the default bridge" if [ ! -s /etc/docker/daemon.json ]; then echo '{"icc": false}' | sudo tee /etc/docker/daemon.json >/dev/null sudo systemctl restart docker.service else echo "/etc/docker/daemon.json exists; leaving it alone (add \"icc\": false yourself)" fi sudo systemctl enable --now docker.service echo "== OpenSandbox server, CLI and MCP server $VERSION" uv tool install --force "opensandbox-server==$VERSION" uv tool install --force "opensandbox-cli==$VERSION" uv tool install --force "opensandbox-mcp==$VERSION" echo "== API key (kept in $DIR/env, mode 600)" if [ ! -s env ]; then (umask 077; echo "OPEN_SANDBOX_API_KEY=$(openssl rand -hex 32)" > env) fi . ./env echo "== ~/.sandbox.toml" (umask 077; cat > "$HOME/.sandbox.toml" <, reachable through the exe.dev proxy. eip = "$VM.exe.xyz" max_sandbox_timeout_seconds = 86400 [log] level = "INFO" [runtime] type = "docker" execd_image = "opensandbox/execd:release-$VERSION" [store] type = "sqlite" path = "~/.opensandbox/opensandbox.db" [docker] network_mode = "bridge" # One host port per sandbox (two with port 8080), inside the range the exe.dev proxy forwards. port_range_min = 4000 port_range_max = 4999 drop_capabilities = ["AUDIT_WRITE", "MKNOD", "NET_ADMIN", "NET_RAW", "SYS_ADMIN", "SYS_MODULE", "SYS_PTRACE", "SYS_TIME", "SYS_TTY_CONFIG"] no_new_privileges = true pids_limit = 4096 [ingress] mode = "direct" [egress] image = "opensandbox/egress:release-$VERSION" mode = "dns+nft" TOML ) echo "== Firewall for sandboxes ($DIR/firewall.sh)" INTEGRATIONS=$(sed -n 's/^INTEGRATIONS=//p' firewall.sh 2>/dev/null || true) cat > firewall.sh </dev/null || iptables -I INPUT -i docker0 -p tcp -m multiport --dports 4000:4999,8080 -j REJECT --reject-with tcp-reset # exe.dev integrations (the LLM gateway and the others on this VM) answer at # 169.254.169.254. block keeps sandboxes away from them (DNS still works); # allow lets code in sandboxes use them. Change it, then: # sudo systemctl restart opensandbox INTEGRATIONS=${INTEGRATIONS:-block} R="DOCKER-USER -i docker0 -d 169.254.169.254 -p tcp ! --dport 53 -j REJECT --reject-with tcp-reset" if [ "\$INTEGRATIONS" = allow ]; then while iptables -D \$R 2>/dev/null; do :; done else iptables -C \$R 2>/dev/null || iptables -I \$R fi FW chmod +x firewall.sh echo "== systemd service" sudo tee /etc/systemd/system/opensandbox.service >/dev/null < py <<'PY' #!/bin/sh # Run Python with the OpenSandbox SDK and this server's API key. set -a; . "$HOME/opensandbox/env"; set +a exec "$HOME/opensandbox/.venv/bin/python" "$@" PY chmod +x py cat > mcp <<'MCP' #!/bin/sh # OpenSandbox's MCP server (stdio), for agents on this VM, with this server's API key. set -a; . "$HOME/opensandbox/env"; set +a exec "$HOME/.local/bin/opensandbox-mcp" --domain localhost:8080 --protocol http "$@" MCP chmod +x mcp echo "== Images" for img in "opensandbox/execd:release-$VERSION" "opensandbox/egress:release-$VERSION" python:3.12-slim opensandbox/desktop:latest; do docker pull -q "$img" done for i in $(seq 30); do curl -fsS localhost:8080/health >/dev/null 2>&1 && break sleep 1 done systemctl is-active opensandbox.service curl -fsS localhost:8080/version; echo echo "API: https://$VM.exe.xyz:8080/docs"