Deployment & Operations
Deploy WS Sandbox Proxy with Docker and Dokploy, configure environment variables, harden production, and run verified backups and restores.
Dokploy on a Linux VPS is the documented production deployment target. WS Sandbox Proxy ships two root Dockerfiles and publishes release images to GitHub Container Registry (GHCR):
| Image | Dockerfile | Role |
|---|---|---|
ghcr.io/flycockpit/ws-sandbox-proxy:vX.Y.Z |
Dockerfile |
API + web SPA + host relay + transfer spool; runs embedded jobs unless WORKER_MODE=external |
ghcr.io/flycockpit/ws-sandbox-proxy-worker:vX.Y.Z |
Dockerfile.worker |
Dedicated BullMQ consumer worker |
[!IMPORTANT] Run exactly one server replica. Host relay sessions, browser/CLI terminal relays, in-process credential revocation notifications, and the
/app/.datatransfer spool all require a singleapps/serverprocess. Always usestop-firstupdates so old and new server containers never mount/app/.datasimultaneously.
Generating a Dokploy Compose deployment
Generate a pinned Compose file and environment checklist from a checkout:
pnpm dokploy:config \
--environment production \
--git-ref release/<commit-sha> \
--url https://wssp.example.com \
--project wssp \
--proxy-network dokploy-network
Useful generator flags:
--topology app(default: single server with embedded jobs + Postgres 18 + Valkey 9noeviction) or--topology app-worker(adds a dedicated worker withWORKER_MODE=external).--backups true: adds the shared/backupsvolume and optionalbackupCompose profile (BACKUP_ENABLED=true,BACKUP_SCHEDULE=daily).--trust-proxy-hops N: defaults to1(Traefik); set2when fronting Traefik with Cloudflare or a Cloudflare Tunnel.--env KEY1,KEY2,...: forwards extra optional server/worker variables (such asIMAGE_S3_*,SANDBOX_OFFLOAD*, orRATE_LIMIT_SDK_KEY_POINTS) without hand-editing Compose.
For a minimal production deploy, generate strong URL-safe secrets with pnpm generate:secrets and inject POSTGRES_PASSWORD, REDIS_PASSWORD, BETTER_AUTH_SECRET, and SANDBOX_REQUEST_HMAC_SECRET in Dokploy. Always keep Valkey configured with maxmemory-policy noeviction so BullMQ never loses jobs.
After deploying, verify the running task generation and /ready commit SHA:
pnpm dokploy:verify --server <service> --url https://wssp.example.com --commit <full-sha>
First admin without email (SETUP_KEY)
If SMTP is not yet configured, you can bootstrap the first verified administrator once:
- Set
SETUP_KEY(32–512 random characters) on the server and deploy. - From a checkout, run
pnpm deploy:generate-adminand supply the server URL,SETUP_KEY, and admin email to generate a 1-hour one-time claim link. - Open the link, set a password (12+ chars), sign in, and enroll 2FA.
- Remove
SETUP_KEYand redeploy. Once any administrator exists (orSETUP_KEYis unset),/api/setup/adminrefuses requests.
Reverse proxy and Cloudflare Tunnel notes
- Persistent transfer spool (
/app/.data): Mount a named volume at/app/.data(owned by UID 1000, mode0700). It stores both/app/.data/transfersand/app/.data/transfers.build-contexton one filesystem. Size it for at leastTRANSFER_DISK_BYTES+TEMPLATE_BUILD_CONTEXT_STAGED_BYTES+ overhead. - WebSockets: Forward
Upgrade,Connection,Origin,Cookie,Authorization, andSec-WebSocket-Protocolunchanged on/ws/sandbox-host,/api/dashboard/sandboxes/{id}/terminal/ws, and/v1/sandboxes/{id}/connect. Do not logSec-WebSocket-Protocol(carries one-use terminal tickets). Set proxy idle timeouts above 60 seconds. - Response compression & downloads: Enable Traefik’s
compressmiddleware on the main router, except on/v1/operations/{id}/contentand/api/dashboard/operations/{id}/content(the generated Compose wires a dedicated higher-priority router without compression so byte ranges andContent-Lengthstay intact). Disable request/response buffering on/v1/transfersand content download routes. - Cloudflare Tunnel (home server): Supported either directly (
cloudflared→server:3000,TRUST_PROXY_HOPS=1) or via Traefik (TRUST_PROXY_HOPS=2withforwardedHeaders.trustedIPsrestricted tocloudflared’s fixed container IP). Turn off Bot Fight Mode / managed challenges on the wssp hostname so daemons and CLIs are never challenged. Never put an S3 image bucket behind Cloudflare’s 100 MB request-body cap.
Environment variables reference
Root .env.example and apps/web/.env.example are generated from scripts/lib/env-manifest.ts (pnpm env:sync / pnpm env:check). Production containers inject variables at runtime and ship no .env file.
Core and security variables
| Variable | Default | Scope | Purpose |
|---|---|---|---|
DATABASE_URL |
required | shared | PostgreSQL 18 connection string |
REDIS_URL |
required | shared | Valkey 9 / Redis connection string (noeviction) |
BETTER_AUTH_SECRET |
required | server | ≥32 random chars; signs sessions, credentials, and password pepper. Rotating invalidates all sessions and product credentials |
BETTER_AUTH_SECRET_PREVIOUS |
unset | server | Previous auth secret during password-pepper rotation only |
BETTER_AUTH_URL |
required | server | Canonical public https:// origin (no path); binds OAuth/MCP issuer and host journal keys |
SANDBOX_REQUEST_HMAC_SECRET |
required | server | ≥64 lowercase hex chars (32 random bytes); derives host journal HMAC keys. Preserve across upgrades |
DATA_ENCRYPTION_KEY |
unset | shared | 64 lowercase hex chars (32 bytes); root HKDF key for webhooks, CLI-login vault, and offloaded disk DEKs. Identical on server & worker |
DATA_ENCRYPTION_KEY_PREVIOUS |
unset | shared | Second root key during pnpm data-key:promote rotation |
ADMIN_EMAILS |
unset | server | Comma-separated bootstrap admin emails |
SIGNUP_ENABLED |
false |
server | Default public signup policy (admins can override in settings) |
SETUP_KEY |
unset | server | Temporary 32–512 char key for first-admin creation without SMTP |
TRUST_PROXY_HOPS |
0 (1 in Dokploy) |
server | Exact trusted reverse-proxy hop count for client IP rate limiting |
MIGRATE_ON_START |
true (server) / false (worker) |
entrypoint | Run committed Prisma migrations before HTTP admission |
Sandbox, relay, MCP, and feature variables
| Variable | Default | Scope | Purpose |
|---|---|---|---|
MCP_ENABLED |
true |
server | Enable/disable /mcp, OAuth provider, and discovery routes |
WSSP_AGENT_TOKEN_ALLOW_NO_EXPIRY |
true |
server | If false, requires expiry on new agent tokens and blocks existing no-expiry tokens (agent_token.no_expiry_blocked) |
WSSP_AGENT_TOKEN_MAX_LIFETIME_DAYS |
90 |
server | Max lifetime (1–3650 days) for newly minted dated agent tokens |
SANDBOX_MAX_TIMEOUT_MS |
86400000 (24 h) |
server | Deployment max lease (300000–2073600000 ms or unlimited) |
SANDBOX_CAPACITY_WAIT_MAX_MS |
3600000 (1 h) |
server | Max pool FIFO queue wait (0 disables, up to 2073600000 or unlimited) |
SANDBOX_CAPACITY_QUEUE_MAX_PER_KEY / _PER_OWNER |
16 / 64 |
server | Queued creates allowed per key / per account (0–100000 or unlimited) |
CAPACITY_RETRY_AFTER_SECONDS |
30 |
server | Retry-After advertised on retryable 409 capacity refusals |
SANDBOX_MAX_HOSTS_PER_OWNER |
20 |
server | Max enrolled hosts per account (1–100000 or unlimited) |
SANDBOX_MAX_SOCKETS_PER_HOST |
2 |
server | Max concurrent relay sockets per host (1–64) |
SANDBOX_EGRESS_BLOCKLIST |
unset | server | Deployment-wide IPv4 CIDRs and domains pushed to every host’s egress guard |
TRANSFER_SPOOL_DIR |
.data/transfers |
server | Persistent spool directory (build-context root is <spool>.build-context) |
TRANSFER_MAX_BYTES / TRANSFER_DISK_BYTES |
1 GiB / 10 GiB |
server | Per-file ceiling (max 1 GiB) and total spool disk budget |
TRANSFER_OWNER_ACTIVE / TRANSFER_GLOBAL_ACTIVE |
4 / 16 |
server | Concurrent active transfer slots |
CREDENTIALS_ENABLED |
true |
shared | Set false (with DATA_ENCRYPTION_KEY kept) for CLI-login drain mode |
CREDENTIAL_MAX_INSTANCES_PER_OWNER |
1000 |
server | Max CLI-login instances per user (1–100000 or unlimited) |
WSSP_CLI_RELEASE_BASE_URL |
GitHub Release | server | Optional HTTPS mirror serving wssp-<target>.tar.xz and sha256.sum for /install.sh |
WEBHOOK_ALLOWED_PRIVATE_CIDRS / _HOSTS |
empty | shared | Optional private webhook destinations (restricted by WEBHOOK_PRIVATE_ALLOWLIST_SCOPE=admins|all) |
WEBHOOK_TRANSLATION_PREFIXES |
empty | shared | Hard-denied RFC 6052 NAT64 prefixes on the worker network |
BACKUP_ENABLED / BACKUP_SCHEDULE |
false / off |
shared | Opt-in automatic pre-migration/pre-drop snapshots and daily backups (BACKUP_HOUR_UTC=3, BACKUP_KEEP=14) |
Production hardening
Before serving real workloads, verify every item:
- Unique secrets & separate custody: Keep
BETTER_AUTH_SECRET,SANDBOX_REQUEST_HMAC_SECRET, andDATA_ENCRYPTION_KEYin the platform secret store and backed up separately from database dumps. LosingDATA_ENCRYPTION_KEYmakes stored webhook secrets, CLI-login values, and offloaded sandbox disks permanently unrecoverable. - Rotating
DATA_ENCRYPTION_KEY: Deploy with the new key inDATA_ENCRYPTION_KEY_PREVIOUSon both server and worker → runpnpm data-key:promote <new-kid>(or Promote in Admin → Observability → Maintenance) → swap the new key intoDATA_ENCRYPTION_KEYand the old key intoDATA_ENCRYPTION_KEY_PREVIOUS→ wait untilpnpm data-key:statusreportssafeToRemove→ removeDATA_ENCRYPTION_KEY_PREVIOUS. - Password pepper: User scrypt hashes are AES-256-GCM sealed under a key derived from
BETTER_AUTH_SECRET. To rotate, stop all server processes, setBETTER_AUTH_SECRET_PREVIOUS=<old>andBETTER_AUTH_SECRET=<new>, restart until logs confirm zero remaining hashes under the previous key, then remove_PREVIOUS. If a key is lost, recover unusable accounts withpnpm auth:pepper:reset-unusable --allow-non-local(followed by--confirm <count>). - CSRF & forced 2FA: Keep
SimpleCsrfProtectionHandlerPlugin(x-csrf-token: orpc) enabled on/rpcand forced 2FA enabled for administrators (FORCE_2FA_DEFAULTS, 24-hour grace from account creation). - Coordinated upgrades: Deploy matching server, worker,
wsspCLI/daemon, and SDK builds from the same release—relay protocol1.0requires coordinated schema/server/daemon releases. Update the server first, then node daemons. - Host hygiene: Run Incus storage pools on encrypted disks with encrypted or disabled swap, and keep
LimitCORE=0inwssp-host.service. - Worker egress defense-in-depth: Filter the worker container’s network egress so it has no route to cloud metadata endpoints or internal management networks in addition to the built-in webhook SSRF checks.
Backup and restore
Automatic backups default off (BACKUP_ENABLED=false) so new deployments run with zero backup dependencies. When you opt in (--backups true, BACKUP_ENABLED=true, BACKUP_SCHEDULE=daily), the deployment takes verified pg_dump custom-format archives daily and automatically before any pending Prisma migration or scheduled contract.sql deletion.
- Off-site S3: Configure
BACKUP_S3_BUCKET, an explicit per-deploymentBACKUP_S3_PREFIX, and a write-only (no-delete) writer keypair. Use a separate ListBucket-onlyBACKUP_MONITOR_S3_*keypair for freshness monitoring—the entrypoint refuses to start if both key IDs match, and unsets writer credentials beforeexecing the app process. - Postgres major upgrades (
PG_MAJOR):pg_dumpcannot dump a newer Postgres major version. When upgrading PostgreSQL, bumpARG PG_MAJORin bothDockerfileandDockerfile.workerand rebuild.
Host helper (app-db.sh) and restore drills
Copy the bundled helper script from the running server container on your Dokploy host:
docker exec <server-container> cat /app/scripts/backup/host.sh > app-db.sh
bash app-db.sh list
bash app-db.sh backup
bash app-db.sh drill
To restore a backup (guided—stops writers, previews the archive, requires typing the target database name, takes a pre-restore safety snapshot, and holds scheduled deletions for 7 days):
bash app-db.sh restore --project <compose-project> daily-20261110T030000Z.dump
For manual one-shot runs on the database network:
docker run --rm --network <db-network> --env-file <protected-env> <image> migrate
docker run --rm --network <db-network> --env-file <protected-env> -v <backups-vol>:/backups <image> backup
docker run --rm --network <db-network> --env-file <protected-env> -v <backups-vol>:/backups <image> restore /backups/<file> --confirm RESTORE:<db> --replace
[!NOTE] Backup scope: PostgreSQL dumps do not include guest VM disks, host receipt journals, the
/app/.datatransfer spool, or S3 offloaded sandbox disk objects. Back up your S3 image bucket separately, and note that shredded offloaded-disk DEKs remain in older database backups until those backups expire from retention.