> ## 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 command in sandbox

> Executes a command in the sandbox. Supports both synchronous and streaming (SSE) modes. Set stream: true to receive output via Server-Sent Events.

Executes a command in the sandbox. Supports both synchronous and streaming (SSE) modes.
Set `stream: true` to receive output via Server-Sent Events.

### Path parameters

<ParamField path="sandboxId" type="string (uuid)" required>
  Unique sandbox identifier
</ParamField>

### Request body

`ExecuteRequest`

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

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

<ParamField body="env" type="object">
  Additional environment variables
</ParamField>

<ParamField body="stream" type="boolean">
  Enable SSE streaming mode
</ParamField>

### Response

`ExecuteResponse`

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

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

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

### Status codes

| Code                                                    | Meaning                                                          |
| ------------------------------------------------------- | ---------------------------------------------------------------- |
| `200`                                                   | Execution result (non-streaming) or SSE stream (streaming mode). |
| In streaming mode, the response is `text/event-stream`. |                                                                  |

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

<ResponseExample>
  ```json 200 theme={null}
  {
    "exit_code": 1,
    "stdout": "string",
    "stderr": "string"
  }
  ```
</ResponseExample>
