CLI, SDK & MCP Reference
Complete wssp CLI command guide, /v1 OpenAPI reference, @wssp/sdk TypeScript examples, and /mcp server setup with all 25 tools.
WS Sandbox Proxy exposes three programmatic interfaces on top of the same owner-scoped sandbox services: the wssp Linux CLI, the /v1 HTTP API (with @wssp/sdk), and the stateless /mcp server for coding agents.
The wssp CLI
wssp has two isolated sides—user commands (talking to /v1 with ~/.local/share/wssp/user/login.json) and host commands (wssp host …, using ~/.local/share/wssp/device-auth.json and ~/.config/wssp/config.toml). The two sides never share credentials or config.
User commands
# Authentication (device flow with browser approval; read or write preset, 1/7/30/90-day expiry)
wssp login --server https://wssp.example.com [--ca-file /path/to/ca.pem]
wssp whoami [--offline]
wssp logout [--local]
# Sandboxes
wssp sandbox create --template <selector> (--pool <id> | --host <id>) [--name <name>] [--cpu N] [--memory MiB] [--disk GiB] [--timeout 2h] [--metadata k=v] [--wait]
wssp sandbox list [--state READY] [--limit 50] [--cursor <cursor>]
wssp sandbox get <sandbox-id>
wssp sandbox stop <sandbox-id> [--wait]
wssp sandbox start <sandbox-id> [--timeout 4h] [--wait]
wssp sandbox destroy <sandbox-id> [--wait]
# Commands & logs
wssp sandbox exec <sandbox-id> [--cwd /path] [--env K=V] [--timeout 10m] [--detach] -- <argv...>
wssp sandbox logs <operation-id> [--follow]
wssp sandbox ps <sandbox-id>
# Interactive shell, port forwards & keyless SSH (requires sandboxes:connect)
wssp sandbox shell <sandbox> [--no-tty] [--cwd /path] [--env LANG=C.UTF-8] [-- <argv...>]
wssp sandbox forward <sandbox> <guestPort>[:<localPort>]... [--address 127.0.0.1] [--unix ./app.sock]
wssp ssh-config [--install] [--yes] [--rotate-host-key]
wssp ssh <sandbox> [-- <ssh-args...>]
# Files (absolute guest paths, resumable 1 MiB chunks up to 1 GiB)
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> /path/in/guest [--output ./local]
wssp sandbox files write <sandbox-id> /path/in/guest --from <local-file|->
wssp sandbox files mkdir <sandbox-id> /path/in/guest
wssp sandbox files mv <sandbox-id> /src /dst
wssp sandbox files rm <sandbox-id> /path/in/guest [--recursive]
# Preview tunnels (requires sandboxes:tunnel)
wssp sandbox ports get <sandbox-id>
wssp sandbox ports expose <sandbox-id> <port>...
wssp sandbox ports set <sandbox-id> [--add <port>]... [--remove <port>]...
wssp sandbox ports link <sandbox-id> <port> [--ttl 300] [--multi-use]
wssp sandbox ports close <sandbox-id>
# Templates & shell completions
wssp template list
wssp template get <template-id>
wssp completions bash|zsh|fish
For CI and non-interactive scripts, export both WSSP_SERVER and WSSP_API_KEY (a dashboard wssp_sdk_… key); together they override any saved wssp login.
Host operator commands
On machines not yet enrolled as hosts, wssp host --help shows only enroll (pass --all to view every subcommand):
wssp host enroll --slug <slug> --server https://wssp.example.com [--ca-file <path>]
wssp host enroll --token-env WSSP_HOST_TOKEN
wssp host run [--runtime incus|fake] [--server <url>] [--host-id <id>] [--host-token-env <VAR>]
wssp host drain [--offload] [--json]
wssp host undrain [--json]
wssp host logout
wssp host config path | show [--json] | init
wssp host config set-ca-file <path> | clear-ca-file
wssp host config set-max-lease <duration|unlimited>
wssp host config set-open-egress-for-others on|off
wssp host config set-egress-block-smtp on|off
wssp host config set-egress-block-external-dns on|off
wssp host config set-egress-dns-upstreams 1.1.1.1,9.9.9.9 | --clear
wssp host config set-accept-foreign-builds on|off
wssp host config set-allow-guest-sudo-for-others on|off
wssp host config set-agent-host-commands on|off
wssp host config set-host-command-max-time <seconds>
wssp host config set-host-file-roots <dir>... | clear-host-file-roots
wssp host config set-host-terminal on|off
sudo wssp host guard install --daemon-user <user> [--configure-ufw|--configure-firewalld]
wssp host guard status [--json]
sudo wssp host guard uninstall
wssp host tunnel install --file <binary> --sha256 <hex> [--max-tunnels 16] [--allow-for-others]
wssp host tunnel status | remove
JSON output and stable exit codes
Every user command accepts --json, printing a single camelCase JSON object to stdout on success or a single {"error":{"code","status","message","data"}} line to stderr on failure.
| Exit code | Meaning |
|---|---|
0 |
Success |
1 |
Runtime, transport, or failed operation error |
2 |
Usage error or server 400/413/415 invalid request |
3 |
Not found (404), including pools outside the login’s grants |
4 |
Host credential inactive (4003 close or 401/403 on host commands) |
5 |
Relay revalidation internal error (1011 close; retry host run) |
6 |
Machine is not an enrolled host |
7 |
Not logged in or user key refused (401) |
8 |
Forbidden: missing scope (403) |
9 |
Limit reached (sandbox.key_limit_reached, quota, or sandbox.capacity_queue_full) |
10 |
Other conflict (409) |
11 |
Retryable server refusal (429, 503, 504) |
125 |
exec/shell/forward/ssh --stdio: wssp failed, session ended, or unknown outcome |
130 |
Interrupted by Ctrl-C |
141 |
Stdout closed early (exec, logs, files read) |
Native /v1 HTTP API
The /v1 API is documented by a generated OpenAPI schema served anonymously at GET /v1/openapi.json (checked in at packages/sandbox-contracts/openapi.json).
- Authentication:
Authorization: Bearer wssp_sdk_…on every route except/v1/openapi.json. No cookies, no CORS grants, no query-string tokens. - Idempotency: All operation-creating mutations require an
Idempotency-Keyheader (1–128 chars fromA-Za-z0-9._:-). Accepted mutations return 202 with{operationId, state, location}. Always retry lost network responses with the same key. - Long-polling: Pass
?waitMs=20000(max25000) onGET /v1/operations/{id},/output, and/resultto wait for state/output changes in one request. - Rate budgets: Default 60-second fail-closed Valkey budgets are 100/key, 300/owner, and 300/IP (
RATE_LIMIT_SDK_*_POINTS), counting reads as well as writes. - Key inspection:
GET /v1/keyreturns the calling key’s metadata, scopes, pools, expiry, and live sandbox limit;DELETE /v1/keyself-revokescliLoginkeys only.
API key scopes
| Scope | Grants |
|---|---|
hosts:read |
List/read visible hosts and agentAccess |
hosts:execute |
Host commands (start/get/stdin/cancel) and queue commands for a person |
hosts:files |
Host file read/list/write/edit within configured roots |
pools:read |
List/read allowed pools and capacity (members also need hosts:read) |
templates:read / templates:write / templates:build |
Read, register/capture, and build template revisions |
sandboxes:read / sandboxes:create / sandboxes:manage / sandboxes:destroy |
Sandbox inspection, creation, rename/stop/reconnect/lease/capture, and deletion |
sandboxes:connect |
CLI shells, command channels, port forwards, and wssp ssh (API keys only) |
sandboxes:tunnel |
Expose, configure, link, and close preview tunnels |
commands:read / commands:execute |
List/connect/tail tracked commands; execute commands and write stdin |
files:read / files:write |
Guest stat/list/download; guest upload/mkdir/move/remove |
operations:read / operations:cancel |
Read operations/results/output; cancel operations (with mutation scope) |
webhooks:write |
Manage webhook endpoints and delivery logs (requires ALL_OWNED + ALL_USABLE) |
credentials:read / credentials:write / credentials:use |
Inspect, manage/upload write-only CLI logins; attach/free on sandboxes |
@wssp/sdk TypeScript client
@wssp/sdk is a server-side ESM TypeScript client for Node 22+ (repo pins Node 26.13.1) with zod as its sole runtime dependency. Never bundle an SDK key into browser code.
[!NOTE]
@wssp/sdkis not yet published to npm. Inside the monorepo, depend on it as"@wssp/sdk": "workspace:*".
Quickstart: create, execute, stream, and transfer files
import { createReadStream, createWriteStream } from "node:fs";
import { stat } from "node:fs/promises";
import { pipeline } from "node:stream/promises";
import { createWsspClient, isWsspError } from "@wssp/sdk";
const wssp = createWsspClient({
baseUrl: "https://wssp.example.com",
apiKey: process.env.WSSP_SDK_KEY!,
});
const sandbox = await wssp.sandboxes.create({
name: "ci-runner",
template: "ubuntu:latest",
poolId: "pool_...",
cpuCount: 2,
memoryMiB: 2048,
diskGiB: 32,
envs: { APP_MODE: "ci" },
allowInternetAccess: true,
lifecycle: { onTimeout: "kill" },
waitForCapacityMs: 5 * 60_000,
});
try {
// Stream command output with automatic long-polling
const build = await sandbox.commands.run(
{ argv: ["make", "test"], cwd: "/home/user/repo", timeoutMs: 10 * 60_000 },
{
onOutput: (event) => {
if (event.kind === "data") process.stdout.write(event.text);
},
},
);
console.log("exitCode:", build.exitCode);
// Resumable streaming upload & download
const { size } = await stat("./repo.tar");
await sandbox.files.upload("/home/user/repo.tar", () => createReadStream("./repo.tar"), {
totalBytes: size,
idempotencyKey: `upload:${sandbox.id}:repo.tar`,
});
const download = await sandbox.files.download("/home/user/report.json");
await pipeline(download.nodeStream(), createWriteStream("./report.json"));
} catch (error) {
if (isWsspError(error)) {
// Branch on error.kind ("capacity", "unknown", "command_exit", "authorization", etc.)
console.error(error.kind, error.code, error.operationId);
}
throw error;
} finally {
await sandbox.destroy();
}
Declarative template builds from the SDK
import { createWsspClient, isBuildFailed, Template } from "@wssp/sdk";
const wssp = createWsspClient({
baseUrl: "https://wssp.example.com",
apiKey: process.env.WSSP_SDK_KEY!,
});
const recipe = Template()
.fromTemplate("ubuntu-26.04")
.aptInstall(["jq"])
.setWorkdir("/home/user/app")
.copy("app/", "./", { owner: "user" })
.runCmd("npm ci")
.egress({ presets: ["ubuntu-apt", "npm"] });
const build = await wssp.templates.build(recipe, {
name: "my-app",
hostId: "host_...",
contextDir: "./context",
timeoutMinutes: 20,
});
if (isBuildFailed(build)) {
throw new Error(`${build.errorCode}: ${build.errorDetail ?? ""}`);
}
Built-in /mcp server
WS Sandbox Proxy serves a stateless, POST-only MCP endpoint at https://wssp.example.com/mcp (enabled by default; disable with MCP_ENABLED=false). It supports MCP 2026-07-28 (JSON responses, primary) and stateless legacy 2025-06-18 (per-request SSE with 15 s keep-alives), with a 1 MiB body cap and no JSON-RPC batching.
Authentication
- OAuth 2.1: Supports PKCE S256, dynamic client registration (DCR), client ID metadata documents (CIMD), and DPoP sender-binding. Issuer:
https://wssp.example.com/api/auth; protected resource:https://wssp.example.com/mcp. Access tokens expire in 600 s; rotating refresh tokens have a 72-hour inactivity window. Browser consent (/{lang}/mcp-consent) selects scopes, resource allowlists, andownSandboxesOnly(defaulttrue). - Agent tokens (
wssp_agent_…): Minted in Settings → Agent tokens (max 10 active tokens per user, default max lifetime 90 days viaWSSP_AGENT_TOKEN_MAX_LIFETIME_DAYS, optional no-expiry controlled byWSSP_AGENT_TOKEN_ALLOW_NO_EXPIRY).
Client setup
Claude Code:
# OAuth 2.1
claude mcp add --transport http wssp https://wssp.example.com/mcp
# Or agent token
claude mcp add --transport http wssp https://wssp.example.com/mcp \
--header "Authorization: Bearer wssp_agent_REPLACE_WITH_YOUR_TOKEN"
Codex (~/.codex/config.toml):
[mcp_servers.wssp]
url = "https://wssp.example.com/mcp"
bearer_token_env_var = "WSSP_AGENT_TOKEN"
For Codex OAuth, omit bearer_token_env_var and run:
codex mcp login wssp --scopes sandboxes:read,hosts:read,offline_access
Rate limits
All /mcp and OAuth buckets are backed by Valkey and fail closed (per minute):
| Boundary | Budget / min | Key |
|---|---|---|
| MCP before auth | 300 | Client IP |
| MCP after auth | 120 | Credential ID |
| Sandbox creates | 30 | Credential ID |
| Host command starts | 30 | Credential ID |
| OAuth protocol requests | 120 | Client IP |
| OAuth consent/continue | 30 | Client IP |
| OAuth dynamic registration | 5 | Client IP |
MCP tool catalog (25 tools)
Tools are advertised only when the credential holds all required scopes; calling a hidden tool returns Tool <name> not found. Wait-capable tools (command_run, file_read, file_list) wait up to 60 seconds per call.
| Tool | Required scopes | Purpose |
|---|---|---|
sandbox_list |
sandboxes:read |
List sandboxes |
sandbox_get |
sandboxes:read |
Read sandbox state and metadata |
sandbox_wait_ready |
sandboxes:read |
Wait for a sandbox to reach READY |
sandbox_create |
sandboxes:create |
Create a new sandbox (with idempotency key) |
sandbox_stop |
sandboxes:manage |
Stop a sandbox and retain disk |
sandbox_destroy |
sandboxes:destroy |
Destroy a sandbox |
sandbox_tunnel_ports |
sandboxes:tunnel |
Add/remove declared preview tunnel ports |
command_run |
commands:execute, commands:read, operations:read |
Start command, wait up to 60 s, return bounded output/result |
command_start |
commands:execute |
Start a tracked command without waiting |
command_output |
commands:read, operations:read |
Read paginated retained command output |
command_stdin |
commands:execute |
Write stdin / EOF to a running command |
command_cancel |
operations:cancel, commands:execute |
Cancel a running command |
file_read |
files:read (+ operations:read to wait) |
Read up to 256 KiB of a guest file (base64) |
file_list |
files:read (+ operations:read to wait) |
List a guest directory |
file_write |
files:write |
Write up to 256 KiB UTF-8 text to a guest file |
host_list |
hosts:read |
List owned hosts (foreign hosts filtered out) |
host_get |
hosts:read |
Read owned host status and agentAccess |
host_command_run |
hosts:execute |
Start a host command on an opted-in owned node |
host_command_get |
hosts:execute |
Poll host command status and masked base64 output |
host_command_cancel |
hosts:execute |
Cancel a running host command |
host_command_queue |
hosts:execute |
Queue a host command for human review |
host_file_read |
hosts:files |
Read masked UTF-8 text inside configured host roots |
host_file_list |
hosts:files |
List a directory inside configured host roots |
host_file_write |
hosts:files |
Write up to 256 KiB UTF-8 text (ETag / createOnly) |
host_file_edit |
hosts:files |
Apply 1–20 atomic {oldText, newText} edits with ETag |