Skip to content
pols.so docs
Esc
↑↓navigate↵open⌘Jpreview
On this page

pols.so API

Control plane API for pols.so developer sandboxes: full Ubuntu 24.04 VMs with root, systemd and Docker.

This file is the source of truth. The Go server interface and client (pkg/api), the TypeScript client (clients/typescript) and the Python client’s types (clients/python/src/pols/_schema.py) are generated from it with make generate.

Authentication: /v1 endpoints require an org-scoped API key as a bearer token (Authorization: Bearer pols_...), except the public /v1/openapi.yaml and /v1/agent-logins, with which an agent gets its first key. The CDP WebSocket endpoint also accepts the connection token described under GET /v1/sandboxes/{sandbox}/browser/cdp.

Agent logins: an agent without a key asks for one by the person’s email address (POST /v1/agent-logins), like OAuth’s device flow (RFC 8628). pols emails the person a link to https://my.pols.so/agent and the short user_code the agent shows too; there they approve or deny, and for an address without an account approving creates it (accepting the terms, and the trial starts) and logs them in. Meanwhile the agent polls POST /v1/agent-logins/token with its device_code every interval seconds until it gets the key, named created by agent on <date> and revocable on the account page like any other. Nothing, account included, is created before the person approves, and the answers never say whether an address has an account.

Agent handoffs: instead, a person logged in on https://my.pols.so/account/agents makes a one-time link like https://my.pols.so/agent/handoff#<token>, for the whole org or limited to some of its sandboxes, and hands it to their agent, which redeems the token after # with POST /v1/agent-logins/handoff (pols login --handoff <link>, or the MCP tool account_handoff). The link is shown once, works once and for 15 minutes, and can be revoked until then.

Roles: an org has users, each an owner, admin or member (see the Role schema), invited by email on the website (https://my.pols.so/account/members). Every user makes their own API keys there, and a key acts with the current role of its user: changing the role changes what the key may do, and removing the user from the org revokes their keys. Every role may use sandboxes, templates, SSH keys and the vault’s names through the API; GET /v1/api-keys lists a member’s own keys only. GET /v1/org says the role of the calling key.

Sandbox-scoped keys: a key made on the website’s API keys page (https://my.pols.so/account/agents, or “Create key for this sandbox” on a sandbox’s page) can be limited to some sandboxes of the org instead of acting in the whole org, and polsd enforces that on every operation. Such a key sees and acts on its sandboxes of the org only. GET /v1/sandboxes lists them alone, and the /v1/sandboxes/{sandbox} operations it may use (get, stats, events and their thumbnails, stop, resume, exec, files, users, computer use, the desktop, CDP, ports and SSH access) answer 404 not_found for any other sandbox, exactly as for one that does not exist. Every other operation answers it 403 forbidden: creating, deleting, forking and renaming sandboxes, timeline settings, templates, sites, GitHub, API keys, the vault, webhooks, billing, usage and the org’s stats. GET /v1/org names its sandboxes (sandboxes) and counts their usage only, GET /v1/orgs lists its own org only, and /v1/ssh-keys shows the SSH keys it registered, which reach its sandboxes only. Port login links, desktop links and CDP connections it makes work only while it may still act on their sandbox. A deleted sandbox leaves its scope; once all of them are deleted the key stops working (401), never widening to the org.

User-limited keys: a key limited to exactly one sandbox can also be limited to one Linux user of it (added under .../users), so that each agent acts as its own user. Such a key runs commands, reads and writes files and logs in over SSH as that user only: omitting user means its user, and asking for root or another user answers 403 forbidden. Files are read and written with that user’s permissions. Its desktop link, computer use, desktop control and CDP are its user’s own desktop and Chrome, likewise: omitting user means its user, and the default user’s desktop or another user’s answers 403 forbidden. Of the sandbox’s operations it may use only get, stats, resume, exec, files, SSH access and those of its user’s desktop; the others answer 403 forbidden, because they act on the sandbox’s other users too: stopping, users, ports and their links, checkpoints and rollback, and its events and their thumbnails (unless its limits allow checkpoint or port; see Key limits below). GET /v1/org names its user (sandbox_user). Once that user is removed from the sandbox the key stops working (401), even if a user of that name is added again. A user with sudo can still become root inside the sandbox.

Key limits: an org owner or admin can give a sandbox-scoped key limits on https://my.pols.so/account/agents, so that an agent adapts its own sandboxes within a budget. Limits name the self-service actions (KeyAction) the key may take, any other being refused, and caps: the largest size it may resize or fork to, what its sandboxes may cost in CPU and RAM per calendar month, and how many sandboxes it may have. A key with limits that allow resize may resize its sandboxes (PATCH /v1/sandboxes/{sandbox} with size only), and one that allows fork may fork them; a fork joins the key’s sandboxes. Limits that leave out checkpoint or port take those away from the key. Past its monthly spend, the key may not resume, resize or fork; its sandboxes that run keep running. A key limited to a sandbox user may be allowed checkpoint, to create and list checkpoints only, and port, never resize or fork. A call beyond the key’s limits answers 403 key_limit, with key_limit saying which limit, the key’s value and its maximum. Keys without limits, every key until an owner or admin sets some, are unchanged. The limits only narrow what the org may do: its quotas, credit and trial limits apply too.

Lifecycle calls are asynchronous. They record the desired state and return at once; a reconciler drives the runtime to it. Poll GET /v1/sandboxes/{sandbox} until status equals desired_state, or until a standby sandbox is stably stopped with status=stopped and desired_state=standby (or is error unless deletion is pending). Conflicting stop/resume requests return 409 until the current transition finishes.

Wherever a path takes {sandbox} or {template}, either the ID (sbx_..., tpl_...) or the org-unique name is accepted.

Computer use: every sandbox has a 1920x1080 X11 desktop and Google Chrome. /computer/* takes screenshots of the whole desktop and drives its mouse and keyboard; coordinates are pixels in that 1920x1080 space, with (0, 0) at the top left. /browser/cdp connects Playwright or Puppeteer to the sandbox’s Chrome over the Chrome DevTools Protocol, proxied by the control plane; Chrome’s debugging port itself only listens inside the sandbox. That desktop is the default sandbox user’s; every user added under .../users has a desktop of its own, with its own Chrome and profile, which these operations and the desktop link reach with user=<name>. A user’s desktop starts on demand and stops after 10 minutes without use.

Edge: the edge serves sandbox content on its own domain (the sandbox domain, on.pols.so in production), never on the API’s or the site’s domain. A published port is at https://<sandbox>-<port>.<sandbox domain>, where <sandbox> is the sandbox’s host_label (a generated name with a random suffix, like braveotterk3f9) or the sandbox ID with _ replaced by -; the desktop is at <sandbox>-desktop and the CDP endpoint at <sandbox>-cdp. Both forms reach the same sandbox with the same login links and tokens. A name given to a sandbox is never part of an address, and the host label never changes, a rename included; no host label is ever given to another sandbox. The VM’s own hostname stays the ID form (sbx-...). An unknown sandbox, a port that is not published and a private port without a valid login link or session all get the same 404 page. Ports are private unless published as public: open them with a login link from POST /v1/sandboxes/{sandbox}/ports/{port}/link, whose token the edge exchanges for a cookie scoped to that one host. The desktop takes no cookie: its link from POST /v1/sandboxes/{sandbox}/desktop carries a token in the URL fragment, which the edge’s desktop page presents when it connects. ssh <sandbox ID>@<gateway> reaches a running sandbox with any key registered under /v1/ssh-keys by a user who is still an active user of the org; a key registered with a sandbox-scoped API key reaches that key’s sandboxes only.

Sites: a site is a static directory published from a sandbox (a build’s dist/, say) and served by pols itself at https://<name>.<sandbox domain>, so it stays up while the sandbox is in standby, stopped or deleted. POST /v1/sites/{site}/versions copies the directory out of the sandbox into a new version and makes it live; versions never change, and .../restore makes an older one live again. POST /v1/sites/{site}/upload publishes the files of a tar or zip archive instead, without a sandbox. A site keeps its newest keep_versions versions besides the live one. Access is private (the org’s users, logged in on the website), link (anyone with the site’s share_url, and the org’s users) or public. Site names share the sandbox domain with sandbox addresses and never collide with them; a name stays the org’s after its site is deleted. The site’s files are billed as disk, with the sandboxes’ and templates’. A site built from a GitHub repository (PUT /v1/sites/{site}/source) is deployed with POST /v1/sites/{site}/deploys: pols builds the commit in a build sandbox of the org and publishes the output as the site’s new live version. A public or link site can have custom domains of the org’s own (/v1/sites/{site}/domains): once the DNS records point to the site, pols verifies the domain and serves the site there too.

Standby: a running sandbox that nothing uses for the deployment’s standby period (15 minutes by default) while its CPU and outbound traffic stay low goes to status standby, using no CPU, unless it was created or updated with keep_awake. On Cloud Hypervisor, the default engine for new sandboxes, its memory is written to disk and it is billed only for that stored memory snapshot, as disk, with no RAM charge (GET /v1/usage); on Incus, the fallback engine and where older sandboxes run, its VM is frozen with its memory kept and billed for the full RAM its size reserves. Its disk keeps being billed. Use means a call on its contents (exec, files, computer use, CDP, a desktop link) or SSH and HTTP through the edge. Any of those wakes it, and so do resuming, forking and saving it as a template: the call waits until the sandbox runs again, usually within a second, and answers 503 waking if that takes longer than the deployment allows. On Cloud Hypervisor a standby whose memory went to disk also gives back the host memory its size reserves, which waking takes again: while its host has no room for it, the wake waits and polsd retries it for up to 10 minutes (waiting_for_capacity_since is set, and calls that wake it answer 503 server_busy with Retry-After); after that it stays in standby with a last_error that says the server was busy. Reading it (GET) does not wake it. A sandbox in standby keeps its place among the org’s running sandboxes, so waking it never fails on the org’s running limit. Once billing is on and the org’s credit is used up, it cannot wake (402 insufficient_credit) and is stopped with the running ones; so too once the org needs a subscription and has none (402 subscription_required). If its VM stopped meanwhile (a host reboot), it shows status stopped with desired state standby, gives up its place and is billed for nothing; the next use boots it like a resume, with the running quota checked, except a fork or template save, which copies its disk without booting it.

Vault: each org has a vault of passwords and environment variables, encrypted at rest. Its owners and admins add, replace and delete entries on the website (https://my.pols.so/account); API keys can only list their names (GET /v1/vault) and name them in secrets when creating or forking a sandbox, which gets each one as an environment variable of that name. No endpoint returns a value. An entry with hosts never enters the sandbox: its variable holds a placeholder, which pols swaps for the value only on the sandbox’s HTTPS requests to those hosts.

Webhooks: the org’s owners and admins register HTTPS endpoints on the website (https://my.pols.so/account) and pick the events each one gets: sandbox.ready, sandbox.stopped, sandbox.error and sandbox.expired. API keys can only list endpoints and their delivery log (GET /v1/webhooks and GET /v1/webhooks/{webhook}/deliveries). Each delivery is a POST of a WebhookEvent JSON body with a Pols-Signature: t=<unix seconds>,v1=<hex> header: the HMAC-SHA256, keyed with the endpoint’s secret (whsec_..., shown once when it is created), of the timestamp, a . and the raw body. Check it in constant time against the raw body before parsing it, refuse timestamps more than 5 minutes from your clock, and process each event id once: a delivery is retried until an endpoint answers 2xx within 10 seconds, with backoff for about a day, so the same event can arrive more than once and out of order.

Billing: GET /v1/billing and PUT /v1/billing read and set who the org’s invoices are made out to, as do the billing page on the website (https://my.pols.so/billing); only owners’ and admins’ keys may (403 forbidden otherwise). A business’s EU or Northern Ireland VAT ID is checked against VIES when it is saved. When VIES does not answer, the details are saved anyway with the VAT ID unverified, and it is checked again later. The details and VIES’s answer decide how VAT applies to the org’s top-ups and subscription (TaxTreatment), and each paid top-up and subscription month gets an invoice (GET /v1/invoices), a PDF kept for 10 years. The subscription (/v1/billing/subscription) costs EUR 10 a month and includes EUR 20 of usage each month, which expires when it renews; an org that needs one (subscription.required on /v1/balance) runs sandboxes only while it has one or its trial credit lasts. Usage beyond the included usage is paid from prepaid credit, and auto top-up (/v1/billing/auto-topup) tops that up by card when it runs low.

Limits: /v1 calls are rate limited per client address and per org, sandbox and template lifecycle calls more tightly, and an org may have only so many exec, file, computer and CDP calls in progress at once. Over a limit the API answers 429 rate_limited with a Retry-After header. A request body that stalls is answered with 408 timeout.

Errors and headers: a failure of the sandbox host is answered with 502 runtime_error and a fixed message; the details are only in the server’s log. A {sandbox} or {template} that is neither a well-formed ID nor a name is 404 not_found. Names and descriptions must be UTF-8 text without control characters other than tab, and exec arguments and paths must not contain NUL. Every response carries X-Content-Type-Options: nosniff, Referrer-Policy: no-referrer, Content-Security-Policy: default-src 'none'; frame-ancestors 'none' and Cache-Control: no-store, except that /v1/openapi.yaml may be cached.

Version 0.1.0
Base URLhttps://api.pols.so

agent-logins

org

api-keys

sandboxes

timeline

exec

files

users

checkpoints

computer

browser

edge

sites

github

ssh-keys

vault

webhooks

billing

templates

databases

usage

system