Skip to content
FlyCockpit
WS Sandbox Proxy/ Sandboxes, SSH & Templates
WS Sandbox Proxy logo

Sandboxes, SSH & Templates

WS Sandbox ProxyRust + TypeScriptMIT
Repository

Create and operate KVM sandboxes, run commands, transfer files, connect over CLI shell or keyless SSH, expose preview tunnels, build templates, and attach CLI logins.

Platforms: Linux with KVM + Incus 6.14+ (or --runtime fake)

Every sandbox is an owner-scoped Incus KVM VM (wssp-sbx-<sandboxId>) booted from an immutable template revision. All state-changing actions run as durable, idempotent operations shared across the dashboard, /v1 HTTP API, wssp CLI, @wssp/sdk, and /mcp.

Creating and managing sandboxes

Create a sandbox by specifying a template selector (slug, slug:tag, template/<logicalId>, or revision/<revisionId>) and exactly one placement target (--pool / poolId or --host / sandboxHostId):

wssp sandbox create --template ubuntu --pool <pool-id> --name ci-runner --cpu 2 --memory 4096 --disk 32 --timeout 2h --wait
wssp sandbox list --state READY --state STOPPED
wssp sandbox get <sandbox-id>
wssp sandbox stop <sandbox-id> --wait
wssp sandbox start <sandbox-id> --wait
wssp sandbox destroy <sandbox-id> --wait

Names, VM sizing, and root disk growth

  • Names: Optional lowercase DNS labels (1–63 characters of a-z, 0-9, inner hyphens; never UUID-shaped or prefixed with wssp-), unique per owner among live sandboxes. When omitted, the server generates an available name such as quiet-otter. Rename any time with PUT /v1/sandboxes/{id}.
  • VM size bounds: cpuCount (1–32), memoryMiB (512–65536 in 256 MiB steps), and diskGiB (minDiskGiB–2048). Omitted dimensions inherit the selected revision’s defaults (new revisions default to 1 vCPU, 1024 MiB RAM, 32 GiB disk). Sizes are fixed at create; there is no in-place resize.
  • Root growth: Requesting a diskGiB larger than minDiskGiB automatically grows the guest partition and filesystem (growpart + resize2fs/xfs_growfs/btrfs) during create readiness. Requesting less than minDiskGiB fails with 400 sandbox.disk_below_image.

Lifecycle states and leases

State Meaning
WAITING_FOR_CAPACITY Queued in a pool FIFO wait queue; holds no host, disk, or lease yet
REQUESTED, SCHEDULED, PROVISIONING Accepted and booting on the assigned host
READY Running and passed guest readiness checks as the template user
STOPPING, STOPPED Clean shutdown (up to ~16 s grace before power-off) with root disk retained
OFFLOADED Stopped with disk stored encrypted in S3; holds no host capacity
RECLAIMING, DELETED Destroyed; VM, bridge, and name freed
UNREACHABLE, HOST_LOST, RECOVERED, ERROR Connectivity or host-reported fault states
  • Leases: Default lifetime is 5 minutes (300000 ms) with lifecycle.onTimeout: "kill" (set "stop" to preserve disk on expiry). The effective maximum lease is min(deployment SANDBOX_MAX_TIMEOUT_MS, host ceiling, pool max, membership max). Unlimited leases (timeoutMs: 0) are permitted only when every layer allows them.
  • Remembered lease: wssp sandbox start / connect({ mode: "cold" }) without a new timeout reuses the sandbox’s most recently requested lifetime.
  • Host-side enforcement: The daemon enforces deadlines locally using monotonic clocks and persisted clock floors—even if disconnected from the control plane.
  • Disk offload: When an S3 image store and DATA_ENCRYPTION_KEY are configured (SANDBOX_OFFLOAD=auto), stopped disks can export encrypted to S3 according to each sandbox’s offload policy (on_stop default, after with afterMs, or on_pressure) and later restore onto any eligible host. (Note: UEFI NVRAM variables are not carried across offloads.)

Command execution and streaming output

Tracked commands execute as the template’s guest user via either script (/bin/bash -lc) or argv (no shell expansion):

wssp sandbox exec <sandbox-id> --cwd /home/user/app --env NODE_ENV=test --timeout 10m -- npm test
wssp sandbox exec <sandbox-id> --detach -- ./long-job.sh
wssp sandbox logs <operation-id> --follow
wssp sandbox ps <sandbox-id>
  • Timeouts: Default command timeout is 120000 ms (max 1800000 ms). Passing timeoutMs: 0 disables the per-command timer (bounded by the sandbox lease and host max_carry cap) when limits.commandTimeoutZero is true.
  • Output retention: The host and server retain the first 256 KiB and rolling final 768 KiB of combined stdout/stderr for 24 hours after completion. Any evicted middle range is reported explicitly as a gap [start, end).
  • Long-polling: GET /v1/operations/{id}, /output, and /result accept waitMs (0–25000) so clients wait efficiently without burning the /v1 request budget.
  • Signals & cancellation: SIGKILL uses canonical operation cancellation (POST /v1/operations/{id}/cancel), killing the command’s process group. SIGTERM/SIGINT/SIGHUP require group-pidfd support on guest kernels ≥ 6.9 (guestApi.supportedSignals); otherwise they refuse cleanly with signal_unsupported_on_guest.
  • Stdin: writeStdin accepts up to 32 KiB decoded per call with optional eof: true.

Resumable file transfers

File payloads move through the server’s transfer spool rather than SQL or JSON:

wssp sandbox files ls <sandbox-id> /home/user --depth 2
wssp sandbox files stat <sandbox-id> /etc/os-release
wssp sandbox files read <sandbox-id> /var/log/app.log --output app.log
wssp sandbox files write <sandbox-id> /home/user/archive.tar --from archive.tar
wssp sandbox files mkdir <sandbox-id> /home/user/data
wssp sandbox files mv <sandbox-id> /home/user/a.txt /home/user/b.txt
wssp sandbox files rm <sandbox-id> /home/user/data --recursive
  • Uploads: Resumable fixed 1 MiB chunks, up to 1 GiB per transfer (TRANSFER_MAX_BYTES), with whole-file SHA-256 verification. Inside the guest, a Python 3 helper stages and fsyncs .wssp-upload-<token> beside the target and atomically renames only upon host commit authorization.
  • Downloads: Captured once from the guest, sealed by SHA-256, and served via HTTP byte ranges (GET /v1/operations/{id}/content, resumable via ETag/If-Range).
  • Path safety: All guest paths must be absolute. Ancestor symlinks and .. are rejected on every operation; reads and uploads also reject final symlinks and non-regular files.

Interactive CLI shell and browser terminal

CLI shell (wssp sandbox shell)

Requires a key with the sandboxes:connect scope (granted to write CLI logins or explicitly selected on an SDK key; never available to MCP tokens):

wssp sandbox shell <sandbox>
wssp sandbox shell <sandbox> -- vim "notes.txt"
wssp sandbox shell <sandbox> --no-tty -- tar -C /srv -cf - data > data.tar

With a local TTY, your terminal switches to raw mode and forwards window resizes (up to 512×1024). Without a TTY (--no-tty or redirected I/O), stdout and stderr stay separate. Sessions are not resumable across disconnects—use tmux or screen inside the guest for long-running interactive work.

Browser terminal

Available on the sandbox detail page (owner cookie session + 2FA policy only):

  • Explicit attach & one-use tickets: Pressing Attach terminal mints a 32-byte, 30-second, single-use ticket carried in Sec-WebSocket-Protocol (never in a URL).
  • Reattach across control-plane restarts: When the host advertises terminalResume, a sandbox terminal survives a host relay reconnect or server restart within terminal_resume_grace (default 120 s, max 10 min).
  • Security & limits: No transcripts are stored (2,000-line browser scrollback only). Dangerous escape sequences (OSC 52 clipboard writes, OSC 8 links, terminal file-transfer sequences) are stripped. Active limit: 1 terminal per sandbox, 8 per host, 4-hour max sandbox terminal lifetime.
  • Mobile utilities: Includes touch keybar (Esc/Tab/Ctrl/Alt + swipe pad), paste review box, pinch text sizing, and photo/camera upload directly into <guest home>/.uploads/.

Port forwarding

Forward local TCP ports or a private 0600 Unix socket to the sandbox’s own loopback (127.0.0.1 / [::1]) over the same WebSocket channel as wssp sandbox shell:

wssp sandbox forward <sandbox> 5432                # 127.0.0.1:5432 -> sandbox:5432
wssp sandbox forward <sandbox> 5432:15432 8080:0   # local 15432 -> 5432, random port -> 8080
wssp sandbox forward <sandbox> 5432 --unix ./pg.sock
  • Reaches only the sandbox’s loopback—never another host or network, and opens no firewall port on the Incus node.
  • Supports up to 32 concurrent connections (plus 32 queued) over one WebSocket, with full half-close and TCP reset propagation. TCP only (no UDP).

Keyless SSH (wssp ssh-config)

Use standard ssh, scp, sftp, rsync, VS Code Remote-SSH, and JetBrains Gateway against any READY sandbox without managing SSH keys or running sshd inside the VM:

wssp ssh-config --install
ssh <sandbox>.wssp
scp ./data.tar <sandbox>.wssp:/home/user/
rsync -a ./src/ <sandbox>.wssp:src/
ssh -L 8080:localhost:8080 <sandbox>.wssp

wssp ssh-config --install writes ~/.ssh/config.d/wssp (with ProxyCommand "/path/to/wssp" ssh --stdio '%n') and prepends Include config.d/wssp at the top of ~/.ssh/config after creating a timestamped backup.

  • How it works: Your local wssp ssh --stdio process acts as the SSH server on stdin/stdout (nothing listens on any socket) and relays channels over /v1/sandboxes/{id}/connect using your saved login.
  • Editor & file-transfer requirements: Community base templates include openssh-sftp-server (for scp, sftp, and JetBrains Gateway) and rsync. Custom templates need those packages installed (no sshd daemon required).
  • Security model: SSH terminates in your local wssp process—traffic is TLS-encrypted per hop, not end-to-end encrypted to the guest (the server and node owner can observe plaintext bytes, just like browser terminals). Agent forwarding (-A), X11 (-X), and reverse forwards (-R) are refused. Local -L/-D forwards reach only the guest’s loopback or guest Unix sockets.

Preview tunnels

When an administrator connects an external Tunnel server and the node owner installs a hash-pinned tunnel client (wssp host tunnel install --file <bin> --sha256 <hex>), sandboxes created with network.tunnelPorts (up to 8 ports) can serve web apps at gated https://<port>-<id>.<zone>/ preview URLs.

The tunnel client runs outside the VM on the host (with tmpfs state under $XDG_RUNTIME_DIR/wssp/tunnels/); the guest cannot alter exposed ports.

wssp sandbox ports expose <sandbox-id> 3000 8080
wssp sandbox ports set <sandbox-id> --add 5173 --remove 8080
wssp sandbox ports link <sandbox-id> 3000 --ttl 300
wssp sandbox ports close <sandbox-id>
  • link mints a short-lived secret URL (default 60 s TTL, single-use, 1 h browser session; pass --multi-use if needed).
  • Individual links can be revoked immediately via DELETE /v1/sandboxes/{id}/tunnel/links/{linkId} without disturbing other links on the tunnel.
  • Stopping, offloading, or destroying a sandbox automatically tears down its tunnel and confirms host client stop (cleanup: "done").

Declarative template builds

Template builds derive a new immutable VM template revision from an existing base template using either a JSON recipe or a supported Dockerfile subset. Builds run in managed KVM VMs on builder hosts and cache by full buildDigest (no Docker layer caching).

JSON recipe

{
  "version": 1,
  "from": { "template": "ubuntu-26.04", "tag": "latest" },
  "args": { "NODE_MAJOR": "22" },
  "steps": [
    { "type": "arg", "name": "NODE_MAJOR", "default": "22" },
    { "type": "run", "script": "apt-get update && apt-get install -y jq", "user": "root" },
    { "type": "env", "values": { "APP_HOME": "/home/user/app" } },
    { "type": "workdir", "path": "${APP_HOME}" },
    { "type": "copy", "src": ["app/", "package.json"], "dest": "./", "owner": "user" },
    { "type": "run", "script": "npm ci" }
  ],
  "resources": { "cpuCount": 2, "memoryMiB": 4096, "diskGiB": 12 },
  "egress": { "mode": "allowlist", "presets": ["ubuntu-apt", "npm"] },
  "scrubPaths": ["/home/user/.cache/npm"]
}

Dockerfile subset and # wssp: extensions

Supported instructions: FROM (single stage, referencing a template slug or revision/<id>), RUN, ENV, ARG, WORKDIR, USER root|user, and COPY [--chown=root|user] [--chmod=<octal>]. Unlike Docker, recipes start as user rather than root; opt into root explicitly per step.

Use # wssp: extension comments for VM-specific fields:

FROM ubuntu-26.04:latest
# wssp:resources cpu=2 memory=4096 disk=12
# wssp:egress-mode allowlist
# wssp:egress-preset ubuntu-apt npm
# wssp:start node /home/user/app/server.js
# wssp:ready curl -fsS http://127.0.0.1:3000/health

USER root
RUN apt-get update && apt-get install -y --no-install-recommends jq
USER user
WORKDIR /home/user/app
COPY --chown=user package.json app/ ./
RUN npm ci
  • Start and ready commands: Revisions with start launch the command on every boot (output logged to /tmp/wssp-start.log) and optionally poll ready (up to readyTimeoutMs, default 60 s) before marking the sandbox READY.
  • Egress presets & hints: Built-in presets (ubuntu-apt, debian-apt, pypi, npm, github) expand to exact domain allowlists. During allowlist builds, a host loopback DNS stub records blocked lookups as step-log hints.
  • Community bases: Create a managed base template (for example ubuntu-26.04) from Templates → Create from community image or client.templates.createFromCommunity(...). Community builds automatically boot and smoke-test a verification VM before publishing.
  • No secrets in recipes: ARG, ENV, and COPY contexts are stored or spooled in plaintext. Never embed tokens or passwords in build inputs.

CLI-login credential vault

CLI logins let sandboxes use authenticated CLI tools (coding agents, cloud CLIs, package registries) without logging in inside every VM. Requires DATA_ENCRYPTION_KEY on the server and worker.

  • Hierarchy: Definition (user-supplied JSON schema describing sign-in command, files, and env vars) → Login (pinned version + delivery settings) → Account (provider account where Pause lives) → Instance (independent encrypted token set) → Lease (active sandbox attachment).
  • Delivery modes:
    • GUEST (default): Installs declared files and env vars into the guest before READY. Exclusive logins copy refreshed token files back to the vault on stop/destroy (and periodically via checkpoints, default every 30 minutes) and scrub the guest disk.
    • PROXY: Keeps API keys strictly in host daemon memory. The daemon runs a strict per-sandbox HTTP/1.1 listener on the bridge gateway (credential_proxy_port, default 48080) that injects the configured auth header on TLS requests to the declared upstream while obeying the host’s egress ceiling.
  • Getting values in: Either launch a dedicated login sandbox in the dashboard (interactive terminal + Save capture) or upload files/env vars via PUT /v1/credentials/{id}/instances/{instanceId}/value. Values are strictly write-only and encrypted with per-value AES-256-GCM keys wrapped under DATA_ENCRYPTION_KEY.
  • Recovery: If a stop fails to save a refreshed token, the lease enters RECOVERY_REQUIRED with the value safely retained on the stopped disk; starting the sandbox recovers it automatically, or you can force-release (optionally promoting the latest checkpoint).
  • Host pinning: Any sandbox that has ever attached a CLI login is permanently restricted to restoring on your own hosts only.