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
The task object
Worker lifecycle
- Enqueue — a caller creates a task with
POST /beta/work. - Lease — a worker calls
GET /beta/work/queue?worker_id=<id>to claim the oldest available task. - Heartbeat — while executing, the worker calls
POST /beta/work/:id/heartbeatto renew the lease and mark the taskrunning. - Complete — the worker calls
POST /beta/work/:id/ackwith a result, orPOST /beta/work/:id/stopto cancel/fail the task.
Endpoints
List tasks
Query parameters
Response
Create a task
Request body
Response
400 Bad Request.
Lease a task
Query parameters
Response when a task is available
Response when the queue is empty
queued task, or a previously leased/running task whose lease has expired (crash recovery).
Heartbeat a task
Request body
Response
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
404 Not Found if the task is already terminal, does not exist, or is leased by a different worker and worker_id is supplied.