Overview

The /beta/work API is a small, poll-based protocol for self-hosted sandbox workers. Instead of pushing jobs to workers, workers lease tasks from a queue using their owning user’s API credentials. Leasing is exclusive: once a worker claims a task, the task moves to leased and is held for 60 seconds. Heartbeats renew the lease and mark the task running. When the job finishes, the worker acknowledges success or stops the task. Tasks may optionally be tied to a session or a deployment so that background work is linked back to the originating resource.

Base URL

All requests require a Bearer token. See Authentication.

The task object

Worker lifecycle

  1. Enqueue — a caller creates a task with POST /beta/work.
  2. Lease — a worker calls GET /beta/work/queue?worker_id=<id> to claim the oldest available task.
  3. Heartbeat — while executing, the worker calls POST /beta/work/:id/heartbeat to renew the lease and mark the task running.
  4. Complete — the worker calls POST /beta/work/:id/ack with a result, or POST /beta/work/:id/stop to cancel/fail the task.
If a worker crashes without heartbeating, its lease expires after 60 seconds and another worker can reclaim the task.

Endpoints

List tasks

Query parameters

Response

Create a task

Request body

Response

Referencing a session or deployment that does not exist returns 400 Bad Request.

Lease a task

Query parameters

Response when a task is available

Response when the queue is empty

Leasing selects the oldest queued task, or a previously leased/running task whose lease has expired (crash recovery).

Heartbeat a task

Request body

Response

Heartbeats return 404 Not Found if the task is not leased by the supplied worker.

Acknowledge a task

Request body

Response

Stop a task

Request body

Response

Stop returns 404 Not Found if the task is already terminal, does not exist, or is leased by a different worker and worker_id is supplied.

Error codes