Execute command with streaming output.
Executes a long-running command in a sandbox and streams stdout/stderr in real-time.
Response Format: NDJSON (Newline Delimited JSON) - each line is a JSON object.
Streaming Behavior:
- Output chunks are sent as they're produced by the command
- When the command completes, a final chunk with exit_code is sent
Client Disconnection:
- When the client closes the connection, the running process is automatically terminated
Example Client Code:
const response = await fetch(url, { method: 'POST', body: JSON.stringify({ command: 'npm run dev' }) });
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const lines = decoder.decode(value).split('\n').filter(Boolean);
for (const line of lines) {
const { stdout, stderr, exit_code } = JSON.parse(line);
if (stdout) process.stdout.write(stdout);
if (stderr) process.stderr.write(stderr);
}
}
post/v1/sandboxes/{id}/execute_async
Path parameters
idstring required
Sandbox ID
Sandbox ID
Request body
Example request
{
"command": "npm run dev"
}Response
Streaming response with NDJSON chunks containing stdout/stderr. Each line is a JSON object.