Exec Runs API

Dispatch commands to a connected remote and read their output. Each exec run is a stored record. Output is stored separately as sequenced chunks.

Requires API key scopes remotes:read (list, get, read output) and remotes:write (dispatch, signal). Create keys in settings → workspace → api keys.

Who can see a run. An exec run is visible to the person who started it (in the workspace it ran for) and to the owner of the remote it ran on. Other teammates, shares, and admin access do not reach it: get, list, output, signal, and the event stream all apply this rule; reading a run you cannot see answers 404, as if it did not exist.

→ Remotes API · Remotes guide


Overview

An exec run is one command executed on a remote. The API creates the run, asks the remote daemon to start the process over the WebSocket, and stores stdout/stderr as sequenced chunks.

ConcernDetail
DispatchPOST /remotes/{id}/execs
StatusPoll GET /execs/{id}
OutputPoll GET /execs/{id}/output?after_seq=N
CancelPOST /execs/{id}/signal
Resume cursorlast_seq on the run. Pass it as after_seq when reconnecting.

The remote must be connected and have exec_enabled: true (start it with belt remote start --exec).

While a run is in progress. Dispatch requires a live connection, but a command already running on the host keeps going if the daemon drops the WebSocket briefly. The API fails unfinished exec runs when the remote reaches stopped (about 30 seconds after disconnect), not when it is merely disconnected. Reconnect the daemon within that window to keep long-running commands alive.


Dispatch exec run

POST /remotes/{remote_id}/execs

Starts a command on a remote the caller owns. Requires remotes:write.

Request

FieldTypeRequiredDescription
commandstringYesProgram to run (for example bash, ls)
argsstring[]NoArguments passed to the command
cwdstringNoWorking directory on the remote
envstring[]NoExtra environment variables (KEY=value)
stdinstringNoWritten to the command's standard input, which is then closed. Up to 4 MiB. It is sent to the daemon and not stored: no API response returns it. Not with pty. Needs belt v1.29.2 or later on the remote.
ptybooleanNoRun under a pseudo-terminal
timeout_msintegerNoTimeout in milliseconds (0 = no limit)
json
1{2  "command": "bash",3  "args": ["-c", "echo hello && uname -a"],4  "cwd": "/home/dev/project",5  "timeout_ms": 600006}
bash
1curl -X POST https://api.inference.sh/remotes/remote_abc123/execs \2  -H "Authorization: Bearer inf_your_key" \3  -H "Content-Type: application/json" \4  -d '{"command":"ls","args":["-la"]}'

Response

Returns an ExecRunDTO. The run is already running when dispatch succeeds.

FieldTypeDescription
idstringExec run ID
remote_idstringTarget remote
commandstringProgram
argsstring[]Arguments
cwdstringWorking directory
envstring[]Names of the extra environment variables the run was given (KEY, without the value). Values are sent to the daemon but never returned by the API.
ptybooleanPseudo-terminal flag
timeout_msintegerRequested timeout
statusstringLifecycle state (see status values)
exit_codeintegerProcess exit code. Omitted until the process exits.
errorstringError message. Omitted when empty.
timed_outbooleantrue when killed by timeout
started_atstringISO timestamp when execution began. Omitted until set.
ended_atstringISO timestamp when the run finished. Omitted until set.
duration_msintegerRun duration. Omitted until the run finishes.
requested_bystringWho initiated the run: user, loop, or agent. This endpoint always records user.
agent_run_idstringAgent run the command belongs to, for agent-initiated runs. Omitted otherwise.
last_seqintegerHighest output sequence number stored. Use it as the resume cursor.

Errors

CodeHTTPWhen
invalid_request400command is empty or the body is not valid JSON
validation_error400stdin is set with pty, or is over 4 MiB
conflict409stdin is set and the remote's belt is older than v1.29.2. Update it with belt update
exec_disabled403Remote has not opted in (exec_enabled: false). Stopped sandboxes are not started for a command when exec is off — start the sandbox with POST /sandboxes/{id}/start first, or reconnect the daemon with exec on
remote_offline409Remote is not connected. A stopped sandbox's remote is started instead; this code is for a running sandbox whose daemon is away
rate_limited42964 runs on this remote are still pending or running. Wait for one to finish. On a sandbox remote, runs from an earlier boot do not count

Get exec run

GET /execs/{id}

Returns a single exec run. Requires remotes:read.

bash
1curl https://api.inference.sh/execs/exec_abc123 \2  -H "Authorization: Bearer inf_your_key"

Poll this endpoint until status is terminal (exited, killed, or denied).


List exec runs

GET /execs or POST /execs/list

Cursor-paginated list. Requires remotes:read. See REST overview: cursor pagination.


Read output

GET /execs/{id}/output?after_seq={n}

Returns output chunks with seq greater than after_seq, in ascending order. Requires remotes:read.

QueryTypeDescription
after_seqintegerReturn chunks after this sequence (default 0, from the start)

Each item is an ExecRunOutputDTO:

FieldTypeDescription
idstringChunk ID
created_atstringISO timestamp when the chunk was stored
exec_run_idstringParent exec run
seqintegerSequence number within the run
streamstringstdout or stderr
datastringOutput bytes as a base64 string. Decode it to get the raw output.
json
1{2  "id": "out_abc123",3  "created_at": "2026-01-01T12:00:00Z",4  "exec_run_id": "exec_abc123",5  "seq": 1,6  "stream": "stdout",7  "data": "aGVsbG8K"8}

A request returns at most 2000 chunks.

Resume after disconnect

  1. Read last_seq from GET /execs/{id}, or track the highest seq you have processed.
  2. Call GET /execs/{id}/output?after_seq={seq} to fetch only newer chunks.
  3. Repeat until the run reaches a terminal status.

last_seq only moves forward. A late or duplicate frame with a lower seq does not rewind it.

bash
1# Fetch chunks after sequence 422curl "https://api.inference.sh/execs/exec_abc123/output?after_seq=42" \3  -H "Authorization: Bearer inf_your_key"

Signal (cancel)

POST /execs/{id}/signal

Asks the remote daemon to kill a running exec. Requires remotes:write. The daemon stops the command's process tree (for example everything started under sh -c), not only the root process.

bash
1curl -X POST https://api.inference.sh/execs/exec_abc123/signal \2  -H "Authorization: Bearer inf_your_key"
json
1{2  "ok": true3}

The response is a bare JSON object without the standard envelope. The call does nothing when the run is already terminal.


Exec run status values

StatusTerminalDescription
pendingNoCreated, not yet sent to the host
runningNoSent to the host
exitedYesProcess ended. exit_code is set.
killedYesEnded without an exit code: signal, timeout, cancel, remote disconnect, or the daemon refused the run
deniedYesThe API could not deliver the command to the daemon

Automatic termination

Some terminal states are applied by the platform when the remote disconnects or you stop the chat:

SituationResult
Remote goes disconnected or stoppedEvery pending or running exec on that remote becomes killed. error is remote disconnected before the command finished. The heartbeat staleness sweep is the grace window—a short network blip that recovers before the remote is marked disconnected does not fail runs.
Chat stoppedExec runs started from an agent's remote_exec in that chat (requested_by: loop, agent_run_id set) are signaled through their execution graph nodes when you stop the chat—the same sweep that cancels running app tasks. In-flight commands do not keep running on the remote after stop.
POST /execs/{id}/signalAsks the daemon to kill the process tree; the run becomes killed when the remote reports exit.
No exit 5 minutes past the timeoutA pending or running run whose exit never arrived is ended 5 minutes after timeout_ms ran out, counted from started_at (or created_at). A timeout_ms of 0 counts as 24 hours. It becomes killed with timed_out: true and error no exit from the box within the run's timeout. The check runs every 10 seconds.

Valid transitions

FromTo
pendingrunning, denied, killed
runningexited, killed

Terminal states are final.


CLI equivalent

bash
1# On the remote machine: opt in to command execution2belt remote --exec34# From any authenticated client: run a command and stream output5belt remote exec remote_abc123 -- ls -la6belt remote exec remote_abc123 -- bash -c "echo hi && uname -a"

belt remote exec dispatches via POST /remotes/{id}/execs, polls GET /execs/{id}/output with after_seq, and exits with the remote command's exit code.

Flags: --cwd, --timeout (seconds), --pty. The command is destructive. belt prompts for confirmation unless --yes is set.


→ Remotes API: register hosts, exec_enabled, WebSocket protocol

→ REST overview: authentication, cursor pagination, response format

Stopped sandboxes

A command sent to the remote of a stopped managed sandbox starts the sandbox first, on its kept disk, and runs once its remote is back — when the remote has exec_enabled: true (the default). The request waits up to 90 seconds for the remote to connect. The caller needs sandboxes:write on the sandbox as well as remotes:write; without it the request fails with 409 and says to start the sandbox first.

SituationResult
Sandbox is stopped and exec is onAuto-start on its kept disk, then dispatch
Sandbox is failed (status_reason set) while it still wants to run409 — a command does not restart it (platform restart rules still apply). Start it with POST /sandboxes/{id}/start or sandbox_start, then send the command again
Sandbox is being deleted409 — the remote names a sandbox whose desired_state is deleted
Start fails, or the sandbox is stopped again while starting409 with the sandbox's status_reason
Start succeeds but the remote does not connect within 90 s409 — try the command again shortly
Remote has exec_enabled: false403 exec_disabled — no auto-start

A sandbox that is running but whose remote is gone answers remote_offline as before. API keys bound to a sandbox's box key never trigger this auto-start path.

we use cookies

we use cookies to ensure you get the best experience on our website. for more information on how we use cookies, please see our cookie policy.

by clicking "accept", you agree to our use of cookies.
learn more.