Running commands
POST /v1/sandboxes/{sandbox_id}/exec runs a command in a running sandbox. It has three modes:
Next step: run the blocking sample below against a sandbox from Sandboxes.
The samples use $SANDBOX for the sandbox ID.
Blocking
A blocking call took about 0.5 seconds on both providers for a command that returns at once.
A command that fails is still a 200. Read exit_code:
The command, cwd, env, and user
command is a string or a list.
- A string runs through
sh -c, so pipes,&&, and variables work. - A list runs as given, with no shell.
Without cwd, a command in python:3.12-slim started in /root on Daytona and in / on Modal. An image with a WORKDIR started there on both.
user works when the user exists in the image:
A user that does not exist returns 400:
Two mistakes do not return an error status. They come back as a 200 with a nonzero exit code:
stderr carries the reason. On Daytona it starts with the path of a wrapper script Meadow uses, for example /tmp/.meadow-fg.Zur2R3/cmd.sh: 2: cd: can't cd to /does/not/exist. Strip that prefix before you show the text to a person or a model.
A command killed for using too much memory is also a 200. On a Daytona sandbox with memory_mb: 1024, a script that kept allocating memory came back with exit_code: 137 and timed_out: false after about 950 MB, and the sandbox stayed running.
There is no terminal (TTY) mode. "tty": true returns 400 unknown field in exec request. For an interactive shell, use SSH.
Timeouts and exit codes
Blocking and streamed commands are killed after 60 seconds unless you set timeout_seconds. A background command has no default timeout.
No single request to the hosted beta lasts longer than 60 minutes, whatever timeout_seconds says. At 60 minutes the load balancer in front of Meadow cuts the request and answers 504 with the text stream timeout. That response is not JSON and has no x-request-id, and it does not tell you how the command ended. Seen on 2026-11-25: a blocking command that was silent for 59 minutes returned in full, and one that was silent for 60 minutes got the 504. Run anything that can take longer as a background command and read it with wait_seconds.
On Daytona:
On Modal:
The exit code of a timed-out command differs by provider and by mode. Read timed_out, or status: timed_out on a background command, and never the exit code.
A timeout ends the command and the processes it started.
Processes a command leaves running
A command that exits by itself leaves the processes it started in the background running. This holds for blocking, streamed and background commands, on Daytona and on Modal. docker exec and both providers’ own exec calls behave the same way.
The command exits at once and the server keeps answering on port 8000 for later commands. This is on the hosted beta since 2026-11-28. It was run on both providers against a build that has the change.
- The process runs until it exits, the sandbox ends, or you
DELETEthe background command that started it. It has no exec ID of its own and does not keep the sandbox from going idle. - A timeout ends the command and every process in its process group.
DELETE /v1/sandboxes/{sandbox_id}/execs/{exec_id}, on a running command or one that has already exited, ends every process that carries the command’sMEADOW_EXEC_IDenvironment variable and, while one of those is still in the command’s session, the rest of that session. That coversnohup ... &,setsid ...and a child that cleared its environment but stayed in the session. A process that cleared its environment and left the session is not ended: end it with another command, such aspkill. For a command that has already exited, the call still returns its final state unchanged.- Redirect the output of a process you leave running, as the example does. If it keeps the command’s
stdoutorstderropen, the command still finishes when it exits by itself: Meadow waits up to about one second for that output and then stops recording. What the process writes later is discarded. Its writes succeed, so it does not block and gets noSIGPIPE.
Streamed
The response has content-type: text/event-stream. Each line arrived about one second after the last:
The same call in Python, with requests. Each data line is JSON, so decode it:
A stream that ends without an exit event did not finish cleanly. A dropped connection loses the rest of the output, and you cannot attach again. For work you cannot afford to lose, use a background command.
Background commands
The command runs inside the sandbox whether or not you stay connected. Use this mode for an agent run, a test suite, a build, or a server. A blocking or streamed call is cut when your connection drops or when the Meadow server that holds it is replaced during a deploy. A background command is not.
Send Idempotency-Key on every background start that you might retry. Without it, each start runs the command again. With it, a repeat with the same body returns the first command, and the same key with a different body returns 409.
Read output
Pass the returned offsets on the next call to get only new output:
wait_seconds (0 to 60) holds the request until there is new output or the command ends. It returns as soon as either happens. Loop until status is no longer running:
state_lost was seen on the hosted beta: after /tmp/.meadow-exec was removed in a Daytona sandbox, reads returned 502 background exec state is unavailable in sandbox; retry for about two and a half minutes, and then the command read failed with failure_reason state_lost. sandbox_lost and provider_unreachable are on the hosted beta since 2026-11-27. Before, a command whose sandbox the provider lost read killed with a null exit_code. New status values and reasons can appear, so treat any status other than running as final.
A long command is not ended by one wrong answer from a provider. If a provider answers “not found” for the sandbox during a read, a kill, a stdin write or a background start, Meadow asks the provider again, up to three times over about 6 seconds. If the sandbox is still there, the call returns 502 with error.code sandbox_unreachable and Retry-After: 2, and every command keeps running: send the call again. A read of a command that has already ended is the exception: it returns 200 with the status, the exit code and the kept last 256 KiB of each stream. A foreground or streamed command gets the same 502. Only when the provider confirms the loss do the commands read failed with sandbox_lost.
The 502 does not go on for ever. If every call about one background command fails this way for 10 minutes, that command reads failed with provider_unreachable. Other commands and the sandbox are not changed. A call that reaches the command starts the count again. This too is on the hosted beta since 2026-11-27. Before, one such answer marked every background command of the sandbox killed while the sandbox still read running. No provider gave such an answer in the sample runs on the hosted beta, so these two paragraphs are read from the server’s code and its tests.
Each read returns at most 1 MiB of each stream. Keep reading from the new offset until stdout and stderr come back empty.
The whole loop in Python: start the command, then read by offset until it has ended and a read comes back empty.
Keep the exec ID. There is no call that lists the commands of a sandbox: GET /v1/sandboxes/{sandbox_id}/execs returns 404 route not found. If you lose the ID, send the start again with the same Idempotency-Key and the same body. The response is the first command, with its ID, and nothing runs twice.
Send input
Start the command with "stdin": true. It cannot be turned on later, and it works in background mode only.
Write to it. Include the newline if the command reads lines. The response is 204:
Read the reply with the read call:
Send "close": true to end the input. The command sees end of file:
One write carries at most 512 KiB. A larger one returns 400 with stdin data exceeds maximum write size. Writing to a command that has ended returns 409 with exec is not running. Writing to a command started without stdin returns 400 with exec was not started with stdin enabled.
Kill
The kill answer carries no output. Read the command again to get what it printed before it died. Killing twice is safe and returns the same answer. A kill ends the command and the processes it started.
Only background commands have an ID, so only they can be killed. A blocking or streamed command stops at its timeout, so set timeout_seconds to fit the work.
Output caps and the truncated flags
When a stream is cut, the body carries stdout_truncated: true or stderr_truncated: true, and the response has the header x-meadow-stdout-truncated: true or x-meadow-stderr-truncated: true. The flags are absent when nothing was cut.
A blocking command that printed 5 MiB:
A command that writes more should write to a file. Fetch the file with the files call.
The full background output 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 after the command ends, including for a command that was still running when you deleted the sandbox or it timed out. After the hour, and after the sandbox is gone, the read call returns the status, the exit code and that kept part. Offsets still count from the start of the stream, so a read from offset 0 of a longer output starts at the kept part and has stdout_truncated set. After 24 hours the output is empty. Nothing is kept when the provider lost the sandbox before Meadow could read it. Seen on the hosted beta, on Daytona: a command that printed 400,000 bytes was read from offset 0 after its sandbox was deleted, and the response held the last 262,144 characters with stdout_truncated: true and stdout_offset: 400000. A command that ended on its own before the delete keeps its real status and exit code, also when nobody read it first: Meadow reads the result of up to 8 unread commands, newest first, just before it deletes the provider sandbox. For a few seconds after the delete call such a command can read killed with a null exit_code, until that read has run. This is on the hosted beta since 2026-11-27. Before, on both providers, a command that had ended and had not been read before the delete read killed with a null exit_code afterwards, and a command read once before the delete kept exited and its exit code. Do: read a background command to its end before you delete the sandbox when you start more than 8 of them.
Errors
Provider differences and rarer cases, such as images without sh on Modal, are in Known limits.
API reference
Operations on this page: execInSandbox, getExec, writeExecStdin, killExec.