Skip to navigation

Read a background command

Returns the status of a background command and its output from the given offsets onward. To follow a command, call this in a loop: pass the stdout_offset and stderr_offset from the last response, and set wait_seconds so the call holds until there is new output, the command ends, or the time passes. Stop when status is no longer running.

Offsets are byte counts. With both offsets at 0 you get the output from the start. One call returns at most 1 MiB of each stream, so keep reading until the offset stops growing.

Limits:

  • Meadow keeps the first 16 MiB of each stream. Output past that is dropped, the offset stops growing, and stdout_truncated or stderr_truncated is true (also sent as X-Meadow-Stdout-Truncated and X-Meadow-Stderr-Truncated response headers). A command that writes more should write to a file.
  • The full output (up to the 16 MiB above) can be read for one hour after the command ends, while the sandbox is running.
  • Meadow also keeps the last 256 KiB of each stream for 24 hours. It takes that copy when the command ends, when the command is killed, and for a command that is still running when the sandbox is deleted or times out. After the hour above, and after the sandbox has ended, this call returns the status, the exit code and that kept part. It does the same for a command that has ended when the vendor cannot find the sandbox for the moment. A command that ended on its own before the sandbox was deleted keeps its real status and exit code, also when it was never read, for up to 8 commands of the sandbox, newest first. Offsets stay byte positions in the whole stream: a read from before the kept part starts at the kept part and sets stdout_truncated or stderr_truncated, and stdout_offset and stderr_offset are the full length of each stream. After the 24 hours the output is empty. The copy is encrypted at rest.
  • Nothing is kept when the vendor lost the sandbox before Meadow could read it, or when a command’s files inside the sandbox were removed. Write results you need to your own storage.
  • If the command’s state inside the sandbox is lost, this call returns 502 for 2 minutes and then reports failed with failure_reason state_lost and a null exit_code. Treat that as an unknown outcome: the command itself may have finished. failed is a new status (2026-11-24). Treat any status other than running as final.
  • If the vendor loses the sandbox while the command runs, the command reads failed with failure_reason sandbox_lost and a null exit_code, and the sandbox reads failed with failure_reason provider_lost. Meadow asks the vendor three times over about 6 seconds before it decides that, so one wrong “not found” from a vendor does not end a command. While the vendor’s answers disagree, this call returns 502 with the code sandbox_unreachable and Retry-After, and the command stays running: call again.
  • If that goes on for 10 minutes for one command, with the vendor still reporting the sandbox as running, the command reads failed with failure_reason provider_unreachable. Its siblings and the sandbox are left alone.

Scope: sandboxes.

Authentication

AuthorizationBearer

A Meadow API key, sent as Authorization: Bearer mdw_.... The header x-api-key: mdw_... is accepted in its place.

Path parameters

sandbox_idstringRequired

The sandbox id returned by POST /v1/sandboxes. It must belong to the key’s project.

exec_idstringRequired

The id returned when the background command was started.

Query parameters

stdout_offsetintegerOptionalDefaults to 0

Byte offset to read stdout from. Use the stdout_offset of the last response. At least 0.

stderr_offsetintegerOptionalDefaults to 0

Byte offset to read stderr from. Use the stderr_offset of the last response. At least 0.

wait_secondsintegerOptional<=60Defaults to 0
Hold the request for up to this many seconds, until there is new output or the command ends. From 0 to 60. A value outside that range returns 400. 0 returns at once.

Response headers

x-request-idstringOptional

Meadow’s id for this request, req_ and 24 hex characters. Every response carries it, including errors, streams and unknown routes. Every error in the Error schema repeats it as request_id. Quote it when you report a problem.

X-Meadow-Stdout-TruncatedenumOptional

true when the command wrote more than 16 MiB to stdout. Absent otherwise.

Allowed values:
X-Meadow-Stderr-TruncatedenumOptional

true when the command wrote more than 16 MiB to stderr. Absent otherwise.

Allowed values:

Response

The command's status and the output from the offsets onward.
idstring
The command id.
statusenum
  • running: still going.
  • exited: ended on its own. Read exit_code.
  • killed: ended by the kill call. killed with a null exit_code means the sandbox was deleted or timed out before the command ended.
  • timed_out: killed at timeout_seconds.
  • failed: Meadow could not learn how the command ended. failure_reason says why. This value is new (2026-11-24): a client with a fixed list of statuses must add it, and should treat any status other than running as final.
Allowed values:
failure_reasonenumOptional

Set when status is failed.

  • state_lost: the command’s state inside the sandbox (its files under /tmp/.meadow-exec, or the process that supervises it) was gone for more than 2 minutes, so the exit code is unknown and exit_code is null. The command itself may have finished.
  • sandbox_lost: the vendor lost the sandbox while the command was running. The sandbox reads failed with failure_reason provider_lost. This value is new (2026-11-24). These commands read killed with a null exit_code before.
  • provider_unreachable: for 10 minutes the vendor answered “not found” or “not running” on every call about this command while it reported the sandbox as running. Meadow stopped tracking this one command. Other commands and the sandbox are not changed. The command itself may still be running. New on 2026-11-24.

More values can be added. Treat one you do not know as an unknown outcome.

Allowed values:
exit_codeinteger or nullOptional
The exit code. Null while running, and when the outcome is unknown.
stdoutstringOptional

Output from stdout_offset onward. Empty in the start and kill responses.

stderrstringOptional

Error output from stderr_offset onward. Empty in the start and kill responses.

stdout_offsetintegerOptional

The byte offset after the returned stdout. Pass this on the next read.

stderr_offsetintegerOptional

The byte offset after the returned stderr. Pass this on the next read.

stdout_truncatedbooleanOptional

True when the command wrote more than 16 MiB to stdout and only the first 16 MiB is kept, or when this read is served from the part Meadow keeps after the sandbox ended and it starts later than the offset you asked for. Absent otherwise.

stderr_truncatedbooleanOptional

True when the command wrote more than 16 MiB to stderr and only the first 16 MiB is kept, or when this read is served from the part Meadow keeps after the sandbox ended and it starts later than the offset you asked for. Absent otherwise.

started_atdatetimeOptional
When the command started.
finished_atdatetime or nullOptional
When the command ended. Null while running.

Errors

400
Bad Request Error
401
Unauthorized Error
403
Forbidden Error
404
Not Found Error
409
Conflict Error
429
Too Many Requests Error
500
Internal Server Error
502
Bad Gateway Error