> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stateset.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Execute a command in a sandbox

> Command result. With stream: true the response is a text/event-stream instead: SSE events with JSON payloads {type: 'stdout'|'stderr', data}, {type:…

### Path parameters

<ParamField path="id" type="string (uuid)" required>
  Sandbox identifier
</ParamField>

### Request body

`ExecuteCommandRequest`

<ParamField body="command" type="string" required />

<ParamField body="working_dir" type="string" />

<ParamField body="env" type="object" />

<ParamField body="stream" type="boolean" />

<ParamField body="timeout" type="integer" />

<ParamField body="sandbox_epoch" type="integer" />

### Response

`object`

<ResponseField name="execution_id" type="string" required>
  Identifier for this execution record
</ResponseField>

<ResponseField name="exit_code" type="integer" required />

<ResponseField name="stdout" type="string" required />

<ResponseField name="stderr" type="string" required />

<ResponseField name="output_truncated" type="boolean">
  Present (true) only when captured output was truncated
</ResponseField>

### Status codes

| Code  | Meaning                                                                                                                                                          |                                                                                                                                                                                                                                                                                              |
| ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `200` | Command result. With `stream: true` the response is a `text/event-stream` instead: SSE events with JSON payloads \`\{type: 'stdout'                              | 'stderr', data}`, `\{type: 'truncated', output\_truncated, message}`(output capped at 8MB),`\{type: 'error', error, code?}`, `\{type: 'exit', code, output\_truncated?}`and`\{type: 'done'}`, each with an SSE `id`usable as`Last-Event-ID`to resume, plus`: heartbeat\` comments every 20s. |
| `202` | Execution queued because the org's concurrent execute limit is reached and queue mode is enabled. `Retry-After` and `X-Stateset-Queue-Position` headers are set. |                                                                                                                                                                                                                                                                                              |
| `404` | Sandbox not found                                                                                                                                                |                                                                                                                                                                                                                                                                                              |

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url 'https://api.sandbox.stateset.app/api/v1/sandbox/{id}/execute' \
    --header "Authorization: Bearer $STATESET_SANDBOX_API_KEY" \
    --header 'Content-Type: application/json' \
    --data '{
    "command": "string",
    "working_dir": "string",
    "env": {},
    "stream": true,
    "timeout": 250,
    "sandbox_epoch": 1
  }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "execution_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "exit_code": 1,
    "stdout": "string",
    "stderr": "string",
    "output_truncated": true
  }
  ```
</ResponseExample>
