Executes a shell command inside the sandbox VM via the envd daemon and returns the
full stdout, stderr, and exit code once the process completes.
For long-running processes, pass background: true to start the command without
waiting. The API returns immediately with a PID that you can use with the
wait and kill endpoints.
For real-time output streaming, use the run-stream
endpoint instead.
Path Parameters
The sandbox identifier. Format: sbx-<8 chars>.
Request Body
The shell command to execute inside the sandbox.Example: "python3 script.py"
When true, start the command in the background and return immediately with
a PID. Use wait to retrieve the result later.
Working directory for the command. Defaults to the envd default (typically
/home/user).Example: "/home/user/project"
Additional environment variables scoped to this command only (merged with
sandbox-level envs).Example: { "DEBUG": "1" }
Per-command timeout in seconds. 0 means no timeout.Example: 30.0
Unix user to run the command as. Defaults to the envd default user.
Reserve a stdin pipe so you can send data later via
send-stdin. Only meaningful when
combined with background: true.
Response
When background is false (default), returns a CommandResult:
Full standard output produced by the command.
Full standard error output produced by the command.
Exit code returned by the process. 0 indicates success.
When background is true, returns a BackgroundProcess:
Process ID assigned to the background command.
Examples
Foreground command
curl -X POST https://api.declaw.ai/sandboxes/sbx-a1b2c3d4/commands \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "cmd": "echo hello" }'
{
"stdout": "hello\n",
"stderr": "",
"exit_code": 0
}
Background command
curl -X POST https://api.declaw.ai/sandboxes/sbx-a1b2c3d4/commands \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "cmd": "sleep 30", "background": true }'
Error Responses
| Status | Cause |
|---|
400 | Invalid request body |
401 | Missing or invalid API key |
404 | Sandbox not found |
409 | Sandbox is paused — resume it before running commands |
410 | Sandbox has been killed |
502 | envd daemon inside the VM is unreachable |
503 | Sandbox has no VM (no guest IP available) |