Docs/Control
API reference

Control

/v1/machines/{machineId}/control — open, run code on, interrupt and close direct control of a machine.

The endpoints behind direct control (research preview). Control is a lease on one machine, so it lives under the machine:

Base URLText
https://api.simular.ai/v1/machines/{machineId}/control

machineId is one of your computers, cloud or your own, from GET /v1/agents/machines. You hold at most one lease per machine, so there is no separate id: the machine is the handle.

Every call carries Authorization: Bearer sapi_..., as everywhere else, or a Tenant token to drive a Tenant's computers. See Authentication.

Open

Open control of a computer
curl -s -X POST "$SAI_API_URL/v1/machines/$MACHINE_ID/control" \
  -H "Authorization: Bearer $SAI_API_KEY"

No body.

201 Created · LeaseJSON
{ "machineId": "m_7f2a", "expiresAfterIdleSec": 600 }

Answers 201 once the lease holds the computer. If a Sai task holds it, or the computer has to start, that can take up to three minutes. If you already hold an open lease on the machine, it answers 200 at once with the same body.

A lease whose computer stopped answering (for example, the service behind it was restarted abruptly) still looks open to this call. The first exec that gets no answer closes it with 410 control_closed and reason unresponsive, and the next open starts a fresh lease.

Who can use a lease

A lease belongs to the credential that opened it: one API key, or your signed-in session in the Playground. Exec, interrupt and get with any other credential answer 404 control_not_open, as if no lease were open; so does close, except for the account owner (below). Opening with another API key answers 409 machine_busy with a holder until the lease is closed or has been idle for about 30 minutes:

409 Conflict · machine_busyJSON
{
  "error": "machine_busy",
  "message": "API key sapi_…a1b2 has control of this computer. Try again once it closes its lease or the lease goes idle. The account owner can also close or take over the lease while signed in.",
  "holder": { "type": "api_key", "last4": "a1b2" }
}

holder.type is api_key (with last4, null for older keys) or playground.

The account owner, signed in with their Sai account rather than an API key, can always take a lease back: opening control closes another credential's lease with reason closed_by_owner and starts a fresh one, and close ends any lease on the machine. An API key cannot do either. After a takeover, the key that held the lease gets 404 control_not_open on its next call (the machine's lease is now the owner's); after the owner closes it, the key gets 410 control_closed with reason closed_by_owner.

Exec

Run code in a lease
curl -s "$SAI_API_URL/v1/machines/$MACHINE_ID/control/exec" \
  -H "Authorization: Bearer $SAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "var r = await machine.exec({ command: '\''hostname'\'' }); r.stdout.trim()",
    "timeoutMs": 60000
  }'
FieldRequiredNotes
codeyesSimulang (JavaScript). Up to 200,000 characters.
timeoutMsnoHow long the block may run. Default 120,000, min 1,000, max 300,000.

Any other field, or a value out of range, answers 400 invalid_body.

200 OK · Exec resultJSON
{
  "result": "WIN-CLOUD-7F2A",
  "logs": [],
  "observations": {},
  "variables": [
    { "name": "r", "type": "object", "preview": "{ stdout: 'WIN-CLOUD-7F2A\\r\\n', … }" }
  ],
  "durationMs": 412
}
FieldNotes
resultThe block's last expression as JSON. A snapshot comes back as its outline text. Over 256 KB, it is truncated to a string.
logsConsole output, oldest first. Up to 200 lines of 2,000 characters.
errorPresent when the block did not finish: { kind, message }.
observations.screenshot{ base64, mimeType }. Present only when this block captured the screen. If it was too large to return, observations.screenshotOmitted is true instead.
variables[{ name, type, preview }] for every variable the REPL holds.
durationMsHow long the block ran.

A block that throws is still a 200. Read error.kind:

kindMeaning
exceptionThe code threw. Variables set before the throw are kept.
timeoutThe block ran past timeoutMs and was stopped, or it waited past timeoutMs behind an earlier block and did not run.
interruptedYou called interrupt.

A stopped block normally keeps the REPL's variables. A block that does not stop within a few seconds of a timeout or interrupt is ended by restarting the REPL, and the earlier variables are gone.

Blocks run one at a time, in the order they arrive. A second exec sent while one is running waits for it, and that wait counts toward its own timeoutMs.

If the lease has ended, exec answers 410 control_closed with a reason:

reasonMeaning
closedYou closed it.
idle_timeoutIt sat idle and released the computer.
lock_lostA Sai task took the computer while the lease was quiet.
unresponsiveThe computer did not answer within the block's timeoutMs plus 30 seconds, so the lease was closed.
shutdownThe service behind the lease restarted.
closed_by_ownerThe account owner closed it while signed in.
410 Gone · control_closedJSON
{
  "error": "control_closed",
  "message": "The computer stopped answering, so this control lease was closed. Open a new one.",
  "reason": "unresponsive"
}

Open control again for a fresh lease. With no lease on the machine at all, exec answers 404 control_not_open.

Interrupt

Interrupt the running block
curl -s -X POST "$SAI_API_URL/v1/machines/$MACHINE_ID/control/interrupt" \
  -H "Authorization: Bearer $SAI_API_KEY"

Stops the running block at its next step or loop iteration. Its exec answers with error.kind: "interrupted".

202 Accepted · Block interruptedJSON
{ "interrupted": true }

false means nothing was running. Answers 202.

Get

Read the lease
curl -s "$SAI_API_URL/v1/machines/$MACHINE_ID/control" \
  -H "Authorization: Bearer $SAI_API_KEY"

Your latest lease on the machine, open or closed.

200 OK · LeaseJSON
{
  "machineId": "m_7f2a",
  "status": "open",
  "createdAt": 1791273600000,
  "lastExecAt": 1791273712000,
  "expiresAfterIdleSec": 600
}

A closed lease has status: "closed" and a closedReason, one of the exec reason values above. createdAt and lastExecAt are milliseconds since the epoch; lastExecAt is null before the first block. A lease that failed to open never replaces the one shown here. 404 control_not_open if you never opened control on the machine.

Close

Close the lease
curl -s -X DELETE "$SAI_API_URL/v1/machines/$MACHINE_ID/control" \
  -H "Authorization: Bearer $SAI_API_KEY"

Clears the REPL and releases the computer. Answers 204, also when no lease is open. Always close when you are done: until then, Sai's tasks on that computer wait.

Errors

Error bodies are { "error": "<code>", "message": "..." }.

StatuserrorWhen
400invalid_machineThe machineId in the path is malformed.
400machine_not_supportedThe computer runs its own Sai agent, so the API cannot drive it.
400invalid_bodyExec: a missing or unknown field, or a value out of range. details lists the problems.
403forbiddenOpen: the computer refused this account.
403own_computer_access_offOpen: your own computer, and code on it is off. Turn it on. For a Tenant's enrolled machine, the Organisation turns it on.
403phone_verification_required, phone_allowance_in_useFree plan: verify a phone number in the Sai app first.
403spend_cap_reachedOpen: the API key reached its monthly spend limit. Carries resetsAt. See Spend limits.
404machine_not_foundNot yours, or does not exist.
404control_not_openNo lease on this machine. Open one first.
409machine_busyA Sai task or another lease holds the computer. Honor Retry-After when set.
409machine_busy with holderOpen: another API key or the Playground holds the lease. See Who can use a lease.
409not_free_tierOpen on the free computer, but the account is no longer on the free plan.
410control_closedThe lease has ended; reason says why (see Exec). Open control again.
429budget_exhaustedFree plan: today's computer time is used up. Resets at midnight UTC.
429rate_limitedMore than 30 leases opened, or 3,000 blocks run, in an hour.
502dispatcher_unavailableOpen: Sai could not reach the computer. Retry shortly.
503machine_unavailable, no_capacityOpen: the computer did not come online in time. Honor Retry-After.

Gotchas

  • new Date() reads your account's clock: the timezone your Sai app last reported, or UTC if you have never opened it, the same clock a learn job's runs use. Use toISOString() or the getUTC* methods when you need UTC.
  • var, not let or const, for anything you want in the next block.
  • Screenshots are base64 in the JSON. Decode before saving; do not log them.
  • The free plan's computer is deleted when the lease closes: copy out anything you need first.
  • Every exec counts as activity. A lease you stop using releases the computer after 10 minutes, or 2 when a Sai task is waiting for it.
© 2026 Simular Inc. All rights reserved.