---
title: "Execute a command and stream output via SSE"
method: POST
path: "/sandboxes/{sandbox_id}/exec/stream"
tags: ["Exec"]
---

# Execute a command and stream output via SSE

`POST /sandboxes/{sandbox_id}/exec/stream`

Runs a command and streams stdout/stderr chunks as Server-Sent Events.
Each event is a JSON payload. The final event includes `exit_code` and
`finished: true`. Idle sandboxes are automatically resumed before execution.

## Request body

- ExecRequest
  - `command` string, required — Command to execute. Wrapped in `/bin/sh -c` unless `args` is provided.
  - `args` string[] — If provided, `command` is used as the binary and `args` as arguments (no shell wrapping).
  - `env` object — Environment variables for the command.
  - `working_dir` string — Working directory (default /home/user).
  - `timeout_s` integer — Timeout in seconds.

## Response `200`

SSE stream. Each line starting with `data: ` contains a JSON `ExecStreamEvent`. The final event has `finished: true`.

## Other responses

- `401` — Missing or invalid API key
- `404` — Resource not found
- `409` — Sandbox is not in a valid state for this operation
- `500` — Internal server error

---

[API](https://skmtc.net/superserve-ai/apis/superserve-api.md) · [All operations](https://skmtc.net/superserve-ai/apis/superserve-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/superserve-ai/superserve-api/revisions/304fe18155b8/schema)
