Sandboxes
26 endpoints at https://api.kosa8.com, sent with Authorization: Bearer $KOSA8_API_KEY. Generated from the API's own OpenAPI description, which a test holds to the router.
List sandboxes, newest first, a page at a time#
/v1/sandboxesscope sandboxes:readWhen next_cursor is not null there are more: call again with cursor set to it.
Parametersallquery · "1"limitquery · integercursorquery · stringnamequery · stringcurl -s -X GET https://api.kosa8.com/v1/sandboxes \ -H "Authorization: Bearer $KOSA8_API_KEY"
Create a sandbox#
/v1/sandboxesscope sandboxes:write201: it is running. 202: a sized or image create booting cold (state creating); poll GET /v1/sandboxes/{id} until running. 404: the snapshot or a named secret is not the org's. 409: a Store item's price changed (price_changed).
ParametersIdempotency-Keyheader · stringtemplatestringaccept_pricenumberregionstringsleep_after_sintegerttl_sintegerlease_sintegerdelete_afterinteger | stringpersistentbooleannohup cmd & keeps running after the exec returns, until the sandbox is deleted (it also keeps the sandbox from sleeping). Default false: commands in the template's image share the sandbox's exec container while it lasts, but one that cannot be had (or another image) runs in a fresh container that shares only /workspace. When true, an exec takes no imagedockerbooleandockerd > /var/log/dockerd.log 2>&1 &, then docker run, docker build and compose work, pulling over the sandbox's egress. Needs a size or image (a sized create) and makes the sandbox persistent. The container gets the privileges dockerd needs inside the sandbox's own microVM, which stays the isolation boundarykvmbooleansize"0.25x0.5" | "0.5x1" | "1x2" | "2x4" | "4x8" | "8x16" | "16x32"cpusnumbermem_mbintegerimagestringdisk_gbintegernamestringcpu"shared" | "dedicated"envobjectsnapshotstringcurl -s -X POST https://api.kosa8.com/v1/sandboxes \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
Get a sandbox#
/v1/sandboxes/{id}scope sandboxes:readidrequiredpath · stringcurl -s -X GET https://api.kosa8.com/v1/sandboxes/$SBX \ -H "Authorization: Bearer $KOSA8_API_KEY"
Change its lifetime or sleep timer#
/v1/sandboxes/{id}scope sandboxes:writeidrequiredpath · stringttl_sinteger | nulldelete_afterinteger | nullsleep_after_sintegercurl -s -X PATCH https://api.kosa8.com/v1/sandboxes/$SBX \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
Delete a sandbox#
/v1/sandboxes/{id}scope sandboxes:writeidrequiredpath · stringcurl -s -X DELETE https://api.kosa8.com/v1/sandboxes/$SBX \ -H "Authorization: Bearer $KOSA8_API_KEY"
Run a command, or start one that keeps running (background: true); a sleeping sandbox wakes first#
/v1/sandboxes/{id}/execscope sandboxes:writeA buffered exec runs at most 90 s: past that the command is stopped and the answer is 504 exec_timeout. For longer commands send stream: true, which is not held to it, or background: true. Commands run in the sandbox's own long-lived container, whose filesystem lasts between commands; one naming another image runs in a fresh container that shares only /workspace. With background: true the answer is 202 at once and the command keeps running after the call (detached, its output to a workspace file): GET /v1/sandboxes/{id}/exec/{exec_id} reports it. Without it, a process the command leaves behind is not guaranteed to outlive it unless the sandbox is persistent. The sandbox's env from create is given to every command, the exec's own env winning per name.
Parametersidrequiredpath · stringcmdrequiredarray of stringimagestringenvarray of stringstreambooleanbackgroundbooleantimeout_sintegercurl -s -X POST https://api.kosa8.com/v1/sandboxes/$SBX/exec \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
A background command: running or exited, its exit code and its output so far#
/v1/sandboxes/{id}/exec/{exec_id}scope sandboxes:readReads its output file (the first MiB) and its exit file; a sleeping sandbox wakes first.
Parametersidrequiredpath · stringexec_idrequiredpath · stringcurl -s -X GET https://api.kosa8.com/v1/sandboxes/$SBX/exec/$EXEC_ID \ -H "Authorization: Bearer $KOSA8_API_KEY"
Stop a background command and what it started (SIGTERM, then SIGKILL after 5 s)#
/v1/sandboxes/{id}/exec/{exec_id}/stopscope sandboxes:writeexited: it had already ended. Its exit code (143 or 137 when stopped) and stopped: true come from GET …/exec/{exec_id}. 409 no_pid: started by an older host, end it with kill.
Parametersidrequiredpath · stringexec_idrequiredpath · stringcurl -s -X POST https://api.kosa8.com/v1/sandboxes/$SBX/exec/$EXEC_ID/stop \ -H "Authorization: Bearer $KOSA8_API_KEY"
A token to send this sandbox's commands to its host directly#
/v1/sandboxes/{id}/directscope sandboxes:writeCreate answers with the same direct object. POST its exec_url with the body of /exec and Authorization: Bearer <token>: the command runs on the sandbox's host without passing through this API, and the answer is /exec's. The token works for exec on this sandbox only, until expires_at (5 minutes); ask here for a fresh one. A sleeping sandbox answers 409 use_api: send that command through /exec, which wakes it. Each command is still in the org's audit log, within seconds.
Parametersidrequiredpath · stringcurl -s -X POST https://api.kosa8.com/v1/sandboxes/$SBX/direct \ -H "Authorization: Bearer $KOSA8_API_KEY"
Snapshot it and free its RAM#
/v1/sandboxes/{id}/sleepscope sandboxes:writeidrequiredpath · stringcurl -s -X POST https://api.kosa8.com/v1/sandboxes/$SBX/sleep \ -H "Authorization: Bearer $KOSA8_API_KEY"
Restore a sleeping sandbox now#
/v1/sandboxes/{id}/wakescope sandboxes:writeidrequiredpath · stringcurl -s -X POST https://api.kosa8.com/v1/sandboxes/$SBX/wake \ -H "Authorization: Bearer $KOSA8_API_KEY"
n copies of the sandbox as it is now, on its host and, when that is full, on others; the rules of a create#
/v1/sandboxes/{id}/forkscope sandboxes:writeCopies land on the parent's host first (a copy-on-write restore of its memory and disk). Up to 1,000 copies a call, made 100 at a time. With partial_ok (the default whenever n is over 100 or a newer field is given), when the parent's host has no room for more, the rest are restored on other hosts (same region first) from a snapshot of the parent copied there: the same state, labels, run_id, lease_s, parent_id and name numbering, priced as a create in that host's region; hosts counts them. That takes longer than a fork on one host (the parent's memory and disk are copied first). Where no other host can take them, the fork stops cleanly: the copies made are returned and the rest are listed in failed with failure_class quota or infra (retryable). The plan's running limit counts copies on every host. partial_ok: false, and a plain {n} of at most 100, are all or nothing and stay on the parent's host. Nothing made is an error answer (with requested, created and failed). A sandbox with secrets cannot be forked (409 secrets): copies never inherit secrets. Progress: send Accept: application/x-ndjson (or ?progress=1) and the answer is 200 NDJSON, one object a line: {"event":"progress","requested","created","failed"} when the copies start and after each host call (up to 100 copies each: a host makes a chunk in one call, so the count moves 100 at a time), then {"event":"result","status", ...} with the fork's own answer and status. A refusal before any copy starts is the plain JSON error. Without it the answer is unchanged.
Parametersidrequiredpath · stringIdempotency-Keyheader · stringnintegerlabelsobjectrun_idstringlease_sintegerprefixstringpartial_okbooleaninherit_secretsbooleancurl -s -X POST https://api.kosa8.com/v1/sandboxes/$SBX/fork \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
Create up to 1,000 sandboxes at once, paced by kosa8#
/v1/sandboxes/batchscope sandboxes:writeEach sandbox is a POST /v1/sandboxes run inside kosa8 (any of its fields apply to every one): the same plan, payment, spending-cap, running-limit and egress rules, and its own audit record. At most 16 are created at a time. Past the plan's running limit a batch makes what fits and lists the rest as failed (code running_limit, failure_class quota); a refusal every later create would meet too (a bad field, a limit, no room on any host) ends it, and the rest are listed as not tried. partial_ok: false is all or nothing: the ones made are deleted and the first refusal is the answer. Nothing made is always an error answer.
ParametersIdempotency-Keyheader · stringcountrequiredintegertemplatestringimagestringsizestringcpusintegermem_mbintegerregionstringttl_sintegerlabelsobjectrun_idstringlease_sintegerprefixstringpartial_okbooleancurl -s -X POST https://api.kosa8.com/v1/sandboxes/batch \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
Extend the leases of a run's sandboxes#
/v1/sandboxes/heartbeatscope sandboxes:writeEach matching sandbox with a lease that has not lapsed gets delete_after = now + (extend_s or its lease_s). A lapsed one is not brought back: the minute tick deletes it. Send it every lease_s / 3 or so; a trainer that crashes stops heartbeating and its sandboxes go within lease_s plus about a minute.
JSON bodyrun_idstringlabelsobjectidsarray of stringextend_sintegercurl -s -X POST https://api.kosa8.com/v1/sandboxes/heartbeat \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
Delete every sandbox of a run (or with labels, or by id)#
/v1/sandboxes/drainscope sandboxes:writeDeletes as DELETE /v1/sandboxes/{id} does, 16 at a time, up to 1,000 a call. Allowed while the organization is frozen.
JSON bodyrun_idstringlabelsobjectidsarray of stringcurl -s -X POST https://api.kosa8.com/v1/sandboxes/drain \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
Grade a solved sandbox in a sealed copy: hidden files, no network, a reward#
/v1/sandboxes/{id}/gradescope sandboxes:writeForks one copy of the sandbox, takes all network away from it (egress deny), writes the hidden files there, runs cmd, reads the reward and deletes the copy. The sandbox graded never sees the files. Each step is held to its own route's rules. A command that does not finish (timeout, a host failing) answers 200 with reward null and its failure_class, so a trainer masks it rather than scoring it 0. 501: the host cannot take the copy's network away, so nothing was run.
Parametersidrequiredpath · stringIdempotency-Keyheader · stringcmdrequiredarray of stringfilesobjecttimeout_sintegerenvarray of stringkeepbooleanrun_idstringrolloutobjectrollout.stepintegerrollout.groupstringrollout.indexintegerrollout.metaobjectcurl -s -X POST https://api.kosa8.com/v1/sandboxes/$SBX/grade \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
TCP ports listening in its running containers#
/v1/sandboxes/{id}/portsscope sandboxes:readidrequiredpath · stringcurl -s -X GET https://api.kosa8.com/v1/sandboxes/$SBX/ports \ -H "Authorization: Bearer $KOSA8_API_KEY"
The Templates gallery: one-click starter sandboxes, each with its size, network, secrets, setup and first win (public, cacheable)#
/v1/gallerypubliccurl -s -X GET https://api.kosa8.com/v1/gallery
One gallery template (public)#
/v1/gallery/{id}publicidrequiredpath · stringcurl -s -X GET https://api.kosa8.com/v1/gallery/$SBX
Launch a gallery template: create its sandbox with every setting it names and start its setup, detached#
/v1/gallery/{id}/launchscope sandboxes:write409 secret_required names the secrets to store first with PUT /v1/secrets/{name}; a launch never carries a secret's value.
Parametersidrequiredpath · stringnamestringsize"2x4" | "4x8" | "8x16" | "16x32"regionstringttl_sintegercurl -s -X POST https://api.kosa8.com/v1/gallery/$SBX/launch \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
Where a gallery launch is (booting, setting_up, ready or failed); starts its setup once the sandbox is up#
/v1/gallery/launches/{id}scope sandboxes:writeidrequiredpath · stringcurl -s -X POST https://api.kosa8.com/v1/gallery/launches/$SBX \ -H "Authorization: Bearer $KOSA8_API_KEY"
Templates the org can create from now: kosa8's, and the org's own (org_templates)#
/v1/templatesscope sandboxes:readcurl -s -X GET https://api.kosa8.com/v1/templates \ -H "Authorization: Bearer $KOSA8_API_KEY"
Build an org template from an image (tag or @sha256 digest) or a Dockerfile, kept as a snapshot new sandboxes restore from#
/v1/templatesscope sandboxes:writePoll GET /v1/templates/{id} until ready, then POST /v1/sandboxes {"template": name}: a restore of its snapshot on the host that built it, not a cold pull. The build runs in a sandbox of the template's size, billed as one; the snapshot is billed as storage and counts toward the plan's snapshots. At most TEMPLATE_BUILDS_PER_ORG (2) build at once; the rest wait queued.
JSON bodynamerequiredstringimagestringdockerfilestringbuild_argsobjectsetup_cmdarray of string | stringsize"2x4" | "4x8" | "8x16" | "16x32"cpusintegermem_mbintegerregionstringcurl -s -X POST https://api.kosa8.com/v1/templates \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
Queue many image templates at once, such as RL task images by digest#
/v1/templates/importscope sandboxes:writeEach image becomes one template and one snapshot: the plan's snapshots limit bounds how many an org keeps (402 plan_limit past it, or failed entries with partial_ok).
JSON bodyimagesrequiredarray of objectsize"2x4" | "4x8" | "8x16" | "16x32"cpusintegermem_mbintegersetup_cmdarray of string | stringregionstringpartial_okbooleancurl -s -X POST https://api.kosa8.com/v1/templates/import \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
An org template, with its build log#
/v1/templates/{id}scope sandboxes:readidrequiredpath · stringcurl -s -X GET https://api.kosa8.com/v1/templates/$SBX \ -H "Authorization: Bearer $KOSA8_API_KEY"
Delete an org template: a build in flight stops and its snapshot is deleted; sandboxes made from it are not touched#
/v1/templates/{id}scope sandboxes:writeidrequiredpath · stringcurl -s -X DELETE https://api.kosa8.com/v1/templates/$SBX \ -H "Authorization: Bearer $KOSA8_API_KEY"