# kosa8 Cloud API > Sealed Linux sandboxes (microVMs) for AI agents and their code, on kosa8's hosts or your own, billed per second. This is the API at https://api.kosa8.com. ## Auth - Make an API key at https://app.kosa8.com/app#keys (it starts k8c_live_; shown once). Send it as `Authorization: Bearer $KOSA8_API_KEY`. - Or sign in from a terminal: `kosa8 login` opens the browser (device flow: `POST /v1/auth/device` `{client, name}`, approve at https://app.kosa8.com/device, then poll `POST /v1/auth/device/token` `{device_code}` every `interval` seconds until 200 `{api_key}`). - Scopes: sandboxes:read, sandboxes:write (includes read), functions:invoke, functions:deploy, keys:manage, audit:read, admin. Give an agent the least it needs, usually sandboxes:write. - Limits: 20 sandboxes running at once by default (sleeping ones do not count; waking one counts it again); past it, 429 `quota_exceeded` with an `agent_message` to relay. `GET /v1/limits` shows where you stand; ask for more with `POST /v1/limits/request {max_running, reason}` (admin key) or `kosa8 cloud limits request N`. - Errors are JSON `{error, message}`. A 402 (`plan_required`, `plan_limit`, `plan_feature`, `payment_required` or `spending_cap_reached`) also has `agent_message` and `upgrade_url`: tell the person the agent_message word for word and stop; do not retry until they act, and never buy a plan yourself. A 503 `no_capacity` is kosa8's hosts being full, not a limit: wait Retry-After seconds and try again. - Every account needs a plan (Solo, Pro, Team or Scale): sign up, add a card, pick a plan (charged now), then use kosa8. `GET /v1/usage` has `plan_usage`: each limit and what is used. ## MCP (for AI agents) - Remote MCP server: POST https://api.kosa8.com/mcp (Streamable HTTP, stateless, JSON-RPC 2.0), same bearer key. - Tools: sandbox_create (size, image, docker, env, snapshot), sandbox_get, sandbox_list, sandbox_exec (background: true for long work), sandbox_exec_status, sandbox_sleep, sandbox_wake, sandbox_delete, sandbox_logs, sandbox_metrics, file_read, file_write, file_list, file_mkdir, file_delete, file_link, code_run, preview_create, preview_list, preview_link, preview_delete, snapshot_create, snapshot_list, snapshot_delete, pipeline_run, pipeline_list, pipeline_get, pipeline_logs, pipeline_cancel, usage_get, templates_list; tools/list has the full set for your key. - Claude Code: `claude mcp add --transport http --scope user kosa8-cloud https://api.kosa8.com/mcp --header "Authorization: Bearer $KOSA8_API_KEY"` - Other clients: https://docs.kosa8.com/guides/cloud-mcp/ ## Main calls - `POST /v1/sandboxes` `{template?, region?, sleep_after_s?, ttl_s?, size?, env?: {"NAME": "value"}, snapshot?}` → 201 `{sandbox: {id, state, …}}`. `env` is given to every command the sandbox runs. `size` ("2x4", "4x8", …) takes a started VM when a template's pool has that size and image (base-2x4), else boots cold (202, poll GET). - `POST /v1/sandboxes/{id}/exec` `{cmd: ["sh","-c","echo hi"], env?: ["NAME=value"], stream?: true}` → `{exit, stdout, stderr}`. A sleeping sandbox wakes first. Commands run in the sandbox's own container: what one writes the next one reads. - Background: `POST /v1/sandboxes/{id}/exec` `{cmd, background: true}` → 202 `{exec: {id, pid, state: "running", output_path}}` at once; the command keeps running after the call and its files are there for later commands. `GET /v1/sandboxes/{id}/exec/{exec_id}` → `{exec: {state: "running"|"exited", exit, output}}`. - Snapshots: `POST /v1/sandboxes/{id}/snapshots` → 201 `{snapshot: {id: "snap_…"}}` (memory, processes, disk; kept after the sandbox is deleted), `POST /v1/sandboxes` `{snapshot: "snap_…"}` makes a new sandbox from it, `GET /v1/snapshots`, `GET|DELETE /v1/snapshots/{id}`. Its storage is billed until it is deleted (see https://kosa8.com/pricing/). - RL rollouts and evals: `POST /v1/sandboxes/batch` `{count: 1..1000, template?, run_id?, lease_s?, prefix?, partial_ok?}` → `{sandboxes, failed, requested, created}`; `POST /v1/sandboxes/heartbeat` `{run_id}` extends leases; `POST /v1/sandboxes/drain` `{run_id}` deletes the run's sandboxes; `POST /v1/sandboxes/{id}/grade` `{cmd, files?: {"/path": ""}}` grades in a sealed copy (no network, hidden files) → `{reward, metrics, exit, failure_class}`. Every error under /v1/sandboxes has `failure_class` (timeout, infra, quota, client) and `retryable`: mask infra rather than scoring it 0. Send `Idempotency-Key` on creates, batches and grades to retry safely. - Org templates: `POST /v1/templates` `{name, image | dockerfile, size?, setup_cmd?}` → 202 (queued, building, ready or failed; poll `GET /v1/templates/{id}`), `POST /v1/templates/import` `{images: [{name, image: "repo@sha256:…"}]}` queues many (RL task images), `DELETE /v1/templates/{id}`. Once ready, `POST /v1/sandboxes` `{template: name}` restores its snapshot instead of pulling the image cold. Each holds one snapshot (the plan's snapshots limit). - A buffered exec runs at most 90 s, then the command is stopped and the answer is 504 `exec_timeout`. For longer commands (installs, test suites, builds) send `stream: true`: the answer is NDJSON frames as the command prints, not held to the 90 s limit. - `GET /v1/sandboxes?limit=&cursor=` (newest first; follow `next_cursor` until it is null), `GET /v1/sandboxes/{id}` - `POST /v1/sandboxes/{id}/sleep` (keeps state, pays only snapshot storage), `POST /v1/sandboxes/{id}/wake` - `DELETE /v1/sandboxes/{id}` - `GET /v1/templates` (what can be created now), `GET /v1/usage` (this month's bill, payment_required) - `GET /v1/recommendations` → `{moments: [{id, kind, title, body, cta: {label, action | href}, reason: {metric, value, threshold}}]}`: at most two offers grounded in the org's own usage (credit running out, a limit reached, yearly billing). Show the person the title and body; never act on a cta yourself (checkouts and plan changes are theirs). `POST /v1/recommendations/{id}/dismiss` hides one for 14 days. - One-call run: `POST /v1/run` `{code, language?} | {command}` (+ files, env, outputs, timeout_s, stream) → `{run: {status, exit, stdout, stderr, files, view_url}}`; a fresh sandbox per call, deleted after. - Functions: `PUT /v1/functions/{name}`, `POST /v1/functions/{name}/invoke` `{event}` - Webhooks: `POST /v1/webhooks` `{url, events?}`; deliveries are signed with `Kosa8-Signature`. - Team: `GET/PUT /v1/sso` single sign-on by OIDC or SAML 2.0 (owner only), SCIM 2.0 provisioning at `https://api.kosa8.com/scim/v2` with a token from `POST /v1/sso/scim-token`. - Security Center: `GET /v1/security/posture` (checklist, passed/total), `GET /v1/security/inventory`, `POST /v1/security/freeze` `{confirm: org name, suspend_keys?}` (new work then answers 423 `org_frozen`), `GET /v1/security/evidence`, audit log streaming at `/v1/security/siem`. ## Example ```sh ID=$(curl -s -X POST https://api.kosa8.com/v1/sandboxes -H "Authorization: Bearer $KOSA8_API_KEY" -H 'Content-Type: application/json' -d '{"template":"python"}' | jq -r .sandbox.id) curl -s -X POST https://api.kosa8.com/v1/sandboxes/$ID/exec -H "Authorization: Bearer $KOSA8_API_KEY" -H 'Content-Type: application/json' -d '{"cmd":["python3","-c","print(6*7)"]}' curl -s -X DELETE https://api.kosa8.com/v1/sandboxes/$ID -H "Authorization: Bearer $KOSA8_API_KEY" ``` ## Reference - [OpenAPI 3.1](https://api.kosa8.com/openapi.json): every /v1 route - [kosa8 Cloud guide](https://docs.kosa8.com/guides/cloud/) - [MCP server](https://docs.kosa8.com/guides/cloud-mcp/) - [GitHub Action](https://docs.kosa8.com/guides/cloud-github-action/) - [Webhook recipes](https://docs.kosa8.com/guides/cloud-webhooks/) - [Pricing](https://api.kosa8.com/v1/pricing)