Skip to content
sandboxrouting

Usage dashboard

From README.md, rendered when the site was built.

A router can report what its ledger records to a dashboard that shows how your workloads spread across providers: sandbox count, sandbox-hours and memory GiB-hours per day and provider, spend against the free usage each provider has left, refusals and failed creates, health and the circuit breaker, live sandboxes with their state as of now, and jobs with every move and why. It is two packages in this repository, both MIT: back/ (an ingest and read API on Postgres) and dashboard/ (Next.js). Reporting is off unless you turn it on.

Self-hosting

cp deploy/.env.example deploy/.env          # set POSTGRES_PASSWORD and SBR_ADMIN_TOKEN
docker compose -f deploy/docker-compose.yml --env-file deploy/.env up -d --build

That runs Postgres, back on port 8787 and the dashboard on port 3000. Sign in with SBR_ADMIN_TOKEN, then make an ingest key for each router under API keys (or set SBR_INGEST_TOKEN too). Each image is configured only by environment variables:

back
DATABASE_URL postgres://… (required). Migrations run at startup and only move forward.
SBR_ADMIN_TOKEN, SBR_INGEST_TOKEN Optional keys for the first account, made if missing and never brought back once revoked. At least 24 characters.
SBR_SWEEP_TOKEN Lets a cron call POST /v1/sweep for every account.
GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET Optional, together: GitHub sign-in instead of admin keys. A first sign-in makes that person's account (one per GitHub user). The OAuth app's callback is <dashboard>/api/auth/github/callback.
SBR_SECRETS_KEY Optional: 32 bytes, base64. Seals the provider keys people save for the hosted router (envelope encryption, a data key per row). SBR_SECRETS_OLD_KEYS lists keys rotated out that still open older rows. SBR_KMS_KEY (a Cloud KMS key name) seals with Cloud KMS instead. Neither: saving provider keys is off.
PORT Default 8787.
dashboard
BACK_URL back as the dashboard's server reaches it (required).
BACK_PUBLIC_URL back as routers reach it, for the setup snippet.
DASHBOARD_PUBLIC_URL The dashboard as browsers reach it, for GitHub's callback. Default: the forwarded host.
PORT Default 3000.

Nothing has to run in the background: whatever changes with time (a sandbox past its deadline, a mark that lapsed, a job whose runner stopped) is worked out when the dashboard reads it, with the database's clock. The sweep only rolls up closed days so reads stay cheap; run it from any cron (curl -X POST -H "authorization: Bearer $SBR_SWEEP_TOKEN" http://back:8787/v1/sweep) or with the compose file's sweep profile. Without Docker, cd back && npm run build && DATABASE_URL=… node dist/main.js and cd dashboard && npm run build && BACK_URL=… npm start; node back/dist/cli.js account create <name> makes an account and prints its admin key.

Turning on the reporter

export SBR_REPORT_URL=http://localhost:8787
export SBR_REPORT_TOKEN=sbrk_…                # an ingest key

or in config:

{ "report": { "url": "https://back.example", "token": "sbrk_…", "metadataKeys": ["team"] } }

SBR_REPORT=0 turns it off for one run. createRouter (and so the CLI, REST server and MCP server) reports when it is on; for a router you construct yourself, wrap its ledger with reportingLedger. Only ids, provider ids, sizes, times, states and prices leave the machine, plus the metadata keys you list. Never commands, env, file contents, provider error messages or keys.

After every ledger write, and when a router starts, the reporter compares the ledger with what it last queued and queues an event for each thing that changed, in an outbox at $SBR_HOME/report/outbox.json (written whole, under a lock, like the ledger). Each event keeps its id until back acknowledges it, and back keeps the newest state of each sandbox, job and mark whatever order events arrive in, so a resend never counts twice. Routing never waits on back: a send times out after 4 s, and a failure backs off (recorded in the outbox, so other processes don't each retry a back end that is down) until the next router to start, or the same long-running one, delivers what is queued. Several quick changes may reach back as one state; the billing segments in it are complete.