> For the list of every page, fetch /llms.txt. The API contract is the OpenAPI file linked from the API reference.

# Run a command

POST https%3A%2F%2Fapi.usemeadow.ai/v1/sandboxes/{sandbox_id}/exec
Content-Type: application/json

Runs a command in a running sandbox. There are three modes. Pick by how long the
command runs and whether you need its output live.

| Mode       | Request            | Response                        | Use for                              |
| ---------- | ------------------ | ------------------------------- | ------------------------------------ |
| Foreground | default            | 200 JSON when the command exits | Short commands.                      |
| Stream     | `stream: true`     | 200 `text/event-stream`         | Watching output as it is written.    |
| Background | `background: true` | 202 with an exec `id`           | Anything long, such as an agent run. |

A command that exits with a code other than 0 is still a 200. Read `exit_code`.

**Foreground.** The response holds `exit_code`, `stdout`, and `stderr`. The
command is killed after `timeout_seconds` (default 60), and the response then
has `timed_out: true`. Each of `stdout` and `stderr` is cut at 4 MiB: the call
still returns 200, with `stdout_truncated` or `stderr_truncated` set and the
response headers `X-Meadow-Stdout-Truncated: true` or
`X-Meadow-Stderr-Truncated: true`. Write large output to a file and download it.

**Stream.** The response is server-sent events. The same 60 second default
timeout applies.

| Event    | `data`                                                                                  | When                                            |
| -------- | --------------------------------------------------------------------------------------- | ----------------------------------------------- |
| `stdout` | A JSON string with a chunk of output                                                    | Zero or more times.                             |
| `stderr` | A JSON string with a chunk of output                                                    | Zero or more times.                             |
| `exit`   | `{"exit_code": 2}`, plus `"timed_out": true` when the command was killed at its timeout | Once, last.                                     |
| `error`  | An `Error` object                                                                       | Once, in place of `exit`, if the stream breaks. |

Decode each `stdout` and `stderr` `data` value as JSON to get the text. A chunk
is not always one line. A captured stream of a command that printed three lines,
wrote one line to stderr and exited with code 2:

```text
event: stdout
data: "line 1\n"

event: stdout
data: "line 2\n"

event: stdout
data: "line 3\n"

event: stderr
data: "warn\n"

event: exit
data: {"exit_code":2}
```

A stream that ends with neither `exit` nor `error` was cut. Treat the outcome as
unknown.

**Background.** The call returns at once. The command keeps running in the
sandbox whether or not you stay connected, so a dropped connection loses
nothing. Read it with `GET /v1/sandboxes/{sandbox_id}/execs/{exec_id}`, send it
input with the stdin call, and stop it with `DELETE`. A background command has
no default timeout: it runs until it exits, is killed, or the sandbox ends. Give
it a `timeout_seconds`, because a running background command also keeps the
sandbox from going idle. Send `Idempotency-Key` on every background start you
may retry. Without it each start runs the command again.

**Rules.**

* A string `command` runs through `sh -c`. An array runs as given, with no shell.
* To detect a timeout read `timed_out` (or the status `timed_out`), never the
  exit code. The code differs by vendor: 143 was seen on Daytona and 124 on
  Modal.
* A command that exits by itself leaves the processes it started in the
  background running, in every mode and on both vendors. They run until they
  exit, the sandbox ends, or you `DELETE` that background command. A timeout
  ends the command's whole process group. A `DELETE` also ends what the command
  left, as `DELETE /v1/sandboxes/{sandbox_id}/execs/{exec_id}` describes. The
  command and its children get the environment variable `MEADOW_EXEC_ID` with
  the exec id.
* A command is finished when the command itself exits, also when a process it
  left behind still holds its `stdout` or `stderr` open. Meadow waits up to
  about one second for that output and then stops recording. What such a
  process writes later is discarded: its writes succeed, and nothing is added
  to `stdout` or `stderr`. Redirect the output of a process you leave running
  to a file.
* On Modal, foreground and stream commands need `sh` in the image, also when
  `command` is an array.
* Background commands keep their state in `/tmp/.meadow-exec` inside the
  sandbox. Leave that directory alone. If another user in the sandbox creates
  that path first, background starts return 400 and name the directory.
* On Modal, a command that cannot be started, for example because `cwd` does not
  exist, returns exit code 128 with the reason on stderr.
* On Modal, ending the whole process group at a timeout needs `mkdir`, `mkfifo`,
  a writable `/tmp` and one of `setsid`, `python3`, or `perl` in the image.
  Without them a timeout ends only the first process.
* With `user` set, do not use the names `_mr`, `_mu_name`, or `_mu_mode` in `env`.
* Unknown fields return 400, and so does a known field set to `null`.

Scope: `sandboxes`.

```bash
curl -sS -X POST "$MEADOW_BASE_URL/v1/sandboxes/$SANDBOX_ID/exec" \
  -H "Authorization: Bearer $MEADOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"command":["python3","-c","print(6*7)"],"timeout_seconds":30}'
```

Reference: https://docs.usemeadow.ai/api-endpoints/sandboxes/exec-in-sandbox

## Authentication

- `Authorization` header (bearer token, required) — A Meadow API key, sent as `Authorization: Bearer mdw_...`. The header `x-api-key: mdw_...` is accepted in its place.

## Request

### Path parameters

- `sandbox_id` (string, required) — The sandbox `id` returned by `POST /v1/sandboxes`. It must belong to the key's project.

### Headers

- `Idempotency-Key` (string, optional) — Makes a retry safe. A repeat with the same key and the same body returns the result of the first call instead of starting again. The same key with a different body returns 409. On `POST /v1/keys`, `POST /v1/projects` and `POST /v1/images` a value is scoped to the API key that sent it: another key that sends the same value starts its own request. The sandbox and exec routes scope it to the API key too. On the exec route the header only has an effect with `background: true`. See Idempotency in the introduction for how long a value is kept. The key is 1 to 255 bytes of printable ASCII. A blank, longer, or non-ASCII key, or the header sent twice, returns 400. A UUID works well.

### Body (application/json)

This endpoint expects an ExecRequest.

- `command` (ExecRequestCommand, required) — The command to run. A string runs through `sh -c`. An array is run as given, with no shell, and its first entry must not be empty.
- `cwd` (string, optional) — Working directory, at most 4096 bytes. Default is the image's working directory.
- `env` (map from string to string, optional) — Extra environment variables for this command, added to the sandbox's own. Keys must not be empty or contain `=`.
- `user` (string, optional) — User name or uid to run as. Default is the image's user. Letters, digits, `_`, `.` and `-`, not starting with `-`. A user that does not exist in the sandbox, or an image with no tool to switch users, returns 400. When the image does not run as root, `env` may not reach the command.
- `timeout_seconds` (integer, optional) — The command is killed when this many seconds pass. At least 1, with no maximum. Default is 60 for the foreground and stream modes. A background command has no default: it runs until it exits, is killed, or the sandbox ends.
- `stream` (boolean, optional, default: false) — Return the output live as server-sent events. Cannot be combined with `background`.
- `background` (boolean, optional, default: false) — Return at once and keep the command running. Cannot be combined with `stream`.
- `stdin` (boolean, optional, default: false) — Background only. Keeps the command's stdin open so input can be sent later with `POST /v1/sandboxes/{sandbox_id}/execs/{exec_id}/stdin`. It cannot be turned on after the command starts.

## Response

### 200

Foreground: the result as JSON. Stream: the events described above.

- `exit_code` (integer, required) — The exit code. Not reliable after a timeout.
- `stdout` (string, required) — Everything the command wrote to stdout, up to 4 MiB.
- `stderr` (string, required) — Everything the command wrote to stderr, up to 4 MiB.
- `timed_out` (boolean, optional) — True when the command was killed at `timeout_seconds`.
- `stdout_truncated` (boolean, optional) — True when `stdout` passed 4 MiB and only the first 4 MiB is returned. Absent otherwise.
- `stderr_truncated` (boolean, optional) — True when `stderr` passed 4 MiB and only the first 4 MiB is returned. Absent otherwise.

### 202

Started in the background. Keep the `id`.

- `id` (string, required) — The command id.
- `status` (enum, required) — - `running`: still going. - `exited`: ended on its own. Read `exit_code`. - `killed`: ended by the kill call. `killed` with a null `exit_code` means the sandbox was deleted or timed out before the command ended. - `timed_out`: killed at `timeout_seconds`. - `failed`: Meadow could not learn how the command ended. `failure_reason` says why. This value is new (2026-11-24): a client with a fixed list of statuses must add it, and should treat any status other than `running` as final.
  - Allowed values: `running`, `exited`, `killed`, `timed_out`, `failed`
- `failure_reason` (enum, optional) — Set when `status` is `failed`. - `state_lost`: the command's state inside the sandbox (its files under `/tmp/.meadow-exec`, or the process that supervises it) was gone for more than 2 minutes, so the exit code is unknown and `exit_code` is null. The command itself may have finished. - `sandbox_lost`: the vendor lost the sandbox while the command was running. The sandbox reads `failed` with `failure_reason` `provider_lost`. This value is new (2026-11-24). These commands read `killed` with a null `exit_code` before. - `provider_unreachable`: for 10 minutes the vendor answered "not found" or "not running" on every call about this command while it reported the sandbox as running. Meadow stopped tracking this one command. Other commands and the sandbox are not changed. The command itself may still be running. New on 2026-11-24. More values can be added. Treat one you do not know as an unknown outcome.
  - Allowed values: `state_lost`, `sandbox_lost`, `provider_unreachable`
- `exit_code` (integer, optional, nullable) — The exit code. Null while running, and when the outcome is unknown.
- `stdout` (string, optional) — Output from `stdout_offset` onward. Empty in the start and kill responses.
- `stderr` (string, optional) — Error output from `stderr_offset` onward. Empty in the start and kill responses.
- `stdout_offset` (integer, optional) — The byte offset after the returned `stdout`. Pass this on the next read.
- `stderr_offset` (integer, optional) — The byte offset after the returned `stderr`. Pass this on the next read.
- `stdout_truncated` (boolean, optional) — True when the command wrote more than 16 MiB to `stdout` and only the first 16 MiB is kept, or when this read is served from the part Meadow keeps after the sandbox ended and it starts later than the offset you asked for. Absent otherwise.
- `stderr_truncated` (boolean, optional) — True when the command wrote more than 16 MiB to `stderr` and only the first 16 MiB is kept, or when this read is served from the part Meadow keeps after the sandbox ended and it starts later than the offset you asked for. Absent otherwise.
- `started_at` (datetime, optional) — When the command started.
- `finished_at` (datetime, optional, nullable) — When the command ended. Null while running.

## Errors

### 400 Bad Request Error

The request breaks a rule, or the sandbox cannot run it as asked: the `user` does not exist, the image has no way to switch users, or the image lacks a tool this mode needs. The message says which.

- `error` (ErrorError, required)
- `request_id` (string, optional) — The same id as the `x-request-id` response header. Quote it when you report a problem.

### 401 Unauthorized Error

The key is missing, malformed, unknown, revoked, or expired, or a key it was minted from no longer exists. Check the key and the header.

- `error` (ErrorError, required)
- `request_id` (string, optional) — The same id as the `x-request-id` response header. Quote it when you report a problem.

### 403 Forbidden Error

The key does not have the `sandboxes` scope. Use a key that has it.

- `error` (ErrorError, required)
- `request_id` (string, optional) — The same id as the `x-request-id` response header. Quote it when you report a problem.

### 404 Not Found Error

No sandbox with this id in the key's project. A sandbox made with a key of another project returns this too, also for an admin key.

- `error` (ErrorError, required)
- `request_id` (string, optional) — The same id as the `x-request-id` response header. Quote it when you report a problem.

### 409 Conflict Error

The sandbox is not `running`, or the `Idempotency-Key` was already used with a different body. A background start can also return 409 when a start with the same `Idempotency-Key` is still in progress (`error.code` `exec_start_in_progress`, with `retry-after`: send the same request again), or when that earlier start failed (`exec_start_failed`: nothing is running and this key can never succeed, so send the start again with a new `Idempotency-Key`).

- `error` (ErrorError, required)
- `request_id` (string, optional) — The same id as the `x-request-id` response header. Quote it when you report a problem.

### 413 Content Too Large Error

The request body is larger than this route allows: 1 MiB for JSON bodies, 16 MiB on the model routes, 100 MiB for a file upload, and 100 MB for a build context.

- `error` (ErrorError, required)
- `request_id` (string, optional) — The same id as the `x-request-id` response header. Quote it when you report a problem.

### 429 Too Many Requests Error

The sandbox vendor rate limited the call, the server instance was full and no slot came free for the account within 3 seconds (`account_in_flight_limit_exceeded`), or too many failed authentications came from your address. Wait for `retry-after` seconds, then retry.

- `error` (ErrorError, required)
- `request_id` (string, optional) — The same id as the `x-request-id` response header. Quote it when you report a problem.

### 500 Internal Server Error

Meadow failed. Retry with backoff, and tell us if it persists.

- `error` (ErrorError, required)
- `request_id` (string, optional) — The same id as the `x-request-id` response header. Quote it when you report a problem.

### 502 Bad Gateway Error

The sandbox vendor failed, refused, or timed out on this call, or the state of a background command could not be read. Retry with backoff. If it persists, read the sandbox with `GET /v1/sandboxes/{sandbox_id}` to see whether it is still `running`. The code `sandbox_unreachable` means the vendor answered "not found" or "not running" for a sandbox that it still reports as running, or Meadow could not tell which. Nothing was changed and no command was ended. The response carries `Retry-After`. Send the call again.

- `error` (ErrorError, required)
- `request_id` (string, optional) — The same id as the `x-request-id` response header. Quote it when you report a problem.

## Types

### ExecRequestCommand

The command to run. A string runs through `sh -c`. An array is run as given, with no shell, and its first entry must not be empty.

- string
- list of string

### ErrorError

- `type` (enum, required) — The class of the failure. - `invalid_request`: the request is malformed or breaks a rule (400), or is too large (413). - `conflict`: the request is valid and the current state refuses it (409). Before 2026-11-24 a 409 used `invalid_request`. - `unauthorized`: the key is missing, unknown, revoked, or expired (401). - `forbidden`: the key's scope or limit does not allow this, or the project's routing is locked (403). - `not_found`: no such resource or route (404). - `no_provider_key`: no stored credential can serve this request (422). - `all_providers_failed`: every vendor in the route was tried (502). - `provider_error`: a vendor failed and no fallback was possible (502). - `rate_limited`: too many requests (429). - `insufficient_quota`: a dollar `limit` on the key, or on a key above it, is spent (402). The name is OpenAI's. - `unavailable`: a dependency Meadow needs is not set up (503). - `internal`: Meadow failed (500), or the feature is not set up (501).
  - Allowed values: `invalid_request`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `no_provider_key`, `all_providers_failed`, `provider_error`, `rate_limited`, `insufficient_quota`, `unavailable`, `internal`
- `message` (string, required) — A sentence for people. It can change, so do not match on it.
- `code` (string, optional) — A stable name for the specific failure. Every Meadow error carries one. `type` stays the general class, and several codes share a type. Branch on `code` when you need to tell two failures of one type apart, for example `api_key_expired` from `api_key_revoked`. The full list is in the Errors guide. A new code can be added at any time, so treat a code you do not know as its `type`. A spent limit (`key_request_limit_exceeded`, `key_token_limit_exceeded`) stays a 403 and not a 429, so a client that retries a 429 does not resend a call a spent key can never make. A spent dollar `limit` (`key_spend_limit_exceeded`) is a 402 for the same reason.
- `param` (string, optional) — The request field, query parameter or header the error is about, when there is one. A nested field is written with dots, such as `credentials.api_key`. Set on most validation errors (400).
- `attempts` (list of Attempt, optional) — The vendors Meadow tried for this request, in order. Present only when it tried at least one.
- `retry` (enum, optional) — Whether to send the same request again. Set on routes under `/v1/sandboxes` only. The values are BoxRouter's (https://boxrouter.ai/docs/error-codes). - `safe`: send the same request again, after `retry-after` seconds when the response has that header. A 429, a 409 `exec_start_in_progress` or `idempotency_request_in_progress`, a 502 `sandbox_unreachable`, and a 5xx on a `GET`, `PUT` or `DELETE`, on `POST /v1/sandboxes/route`, or on a sandbox create or background command start sent with `Idempotency-Key`. - `after_fix`: change the request, the key or the account first. Any other 4xx. - `check_outcome`: read the sandbox or the command before you send it again, because the work may have happened. A 5xx on any other `POST`, which includes a blocking command. - `never`: do not send it again. A 501. When the response has `x-should-retry`, `retry` is `safe` exactly when the header is `true`.
  - Allowed values: `safe`, `after_fix`, `check_outcome`, `never`
- `outcome` (enum, optional) — What happened to the work. Set on routes under `/v1/sandboxes` only. The values are BoxRouter's (https://boxrouter.ai/docs/error-codes). - `not_started`: nothing was changed. Every 4xx, a 501, and a 502 `sandbox_unreachable`. - `unknown`: the work may have happened. Any other 5xx. - `completed` and `partial`: the work happened, in whole or in part. Meadow does not send them today. Handle them as `unknown`. A sandbox create that fails after Meadow accepted it is not an error response: the create returns 202, and the sandbox later has `status` `failed` and a `failure_reason`.
  - Allowed values: `not_started`, `completed`, `partial`, `unknown`

### Attempt

One try at one vendor, for a model call or a sandbox create.

- `provider` (enum, required) — The name of a vendor. Model providers and sandbox providers share one list. Model providers: `anthropic`, `openai`, `google`, `xai`, `azure`, `bedrock`, `vertex`, `openrouter`, `fireworks`, `deepseek`. Sandbox providers: `daytona`, `modal`.
  - Allowed values: `anthropic`, `openai`, `google`, `xai`, `azure`, `bedrock`, `vertex`, `openrouter`, `fireworks`, `deepseek`, `daytona`, `modal`
- `outcome` (enum, required) — How the try ended. - `served`: this vendor served the request. - `unsupported`: the vendor cannot do what was asked, such as a resource size, a network rule, or a model it does not offer. - `refused`: the vendor rejected the request or the stored credential. - `no_capacity`: the vendor had no capacity. - `timeout`: the vendor did not answer in time. - `rate_limited`: the vendor answered 429. - `error`: any other failure.
  - Allowed values: `served`, `unsupported`, `refused`, `no_capacity`, `timeout`, `rate_limited`, `error`
- `reason` (enum, optional) — A stable code for why the try ended as it did. It is narrower than `outcome`, and it is the code to branch on or to count. More values can be added: treat one you do not know like `vendor_error`. - `served`: this vendor served the request. - `no_capacity`: the vendor had no capacity. - `quota_exceeded`: the vendor account is out of quota or credit. - `rate_limited`: the vendor answered 429. - `timeout`: the vendor did not answer in time. - `auth_failed`: the vendor rejected the stored vendor key. - `invalid_request`: the vendor rejected the request itself. - `refused`: the vendor refused for another reason. - `unsupported`: the vendor cannot do what was asked, such as a model, a GPU type, a size or a network rule. - `no_provider_key`: skipped, because no usable vendor key was stored. - `image_pull_failed`, `build_failed`: the vendor could not pull or build the image (sandboxes). - `provider_lost`: the vendor lost the sandbox while it was starting. - `vendor_error`: any other failure.
  - Allowed values: `served`, `no_capacity`, `quota_exceeded`, `rate_limited`, `timeout`, `auth_failed`, `invalid_request`, `refused`, `unsupported`, `no_provider_key`, `image_pull_failed`, `build_failed`, `provider_lost`, `vendor_error`
- `started_at` (datetime, optional) — When Meadow started this try. Absent on attempts recorded before 2026-11-24.
- `finished_at` (datetime, optional) — When this try ended.
- `detail` (string, optional) — A short description of what happened, written by Meadow, such as `provider returned HTTP 404`. On a `served` sandbox attempt it reports resources the vendor granted that differ from the request, such as `provider granted cpu 2 instead of 1.5` or `gpu type H200 instead of H100`. It says `provider built a copy of the image for this size` when this create made a new Daytona snapshot for an `image_id`. On an `unsupported` attempt it carries the vendor's size limit, such as `daytona cannot serve this size: CPU request 8 exceeds maximum allowed per sandbox (4)`. Absent when there is nothing to say.
- `duration_ms` (integer, optional) — How long the try took, in milliseconds.

## Examples

### A command that exited with code 3

**Response**

```json
{
  "exit_code": 3,
  "stdout": "hi from root in /tmp\n",
  "stderr": "oops\n",
  "timed_out": false
}
```

**SDK Code**

```python A command that exited with code 3
import requests

url = "https://api.example.com/v1/sandboxes/sbx_0000be20/exec"

headers = {
    "Idempotency-Key": "00000000-0000-0000-0000-000000007779",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript A command that exited with code 3
const url = 'https://api.example.com/v1/sandboxes/sbx_0000be20/exec';
const options = {
  method: 'POST',
  headers: {
    'Idempotency-Key': '00000000-0000-0000-0000-000000007779',
    Authorization: 'Bearer <token>'
  }
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go A command that exited with code 3
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.example.com/v1/sandboxes/sbx_0000be20/exec"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("Idempotency-Key", "00000000-0000-0000-0000-000000007779")
	req.Header.Add("Authorization", "Bearer <token>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby A command that exited with code 3
require 'uri'
require 'net/http'

url = URI("https://api.example.com/v1/sandboxes/sbx_0000be20/exec")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '00000000-0000-0000-0000-000000007779'
request["Authorization"] = 'Bearer <token>'

response = http.request(request)
puts response.read_body
```

```java A command that exited with code 3
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.example.com/v1/sandboxes/sbx_0000be20/exec")
  .header("Idempotency-Key", "00000000-0000-0000-0000-000000007779")
  .header("Authorization", "Bearer <token>")
  .asString();
```

```php A command that exited with code 3
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.example.com/v1/sandboxes/sbx_0000be20/exec', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Idempotency-Key' => '00000000-0000-0000-0000-000000007779',
  ],
]);

echo $response->getBody();
```

```csharp A command that exited with code 3
using RestSharp;

var client = new RestClient("https://api.example.com/v1/sandboxes/sbx_0000be20/exec");
var request = new RestRequest(Method.POST);
request.AddHeader("Idempotency-Key", "00000000-0000-0000-0000-000000007779");
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift A command that exited with code 3
import Foundation

let headers = [
  "Idempotency-Key": "00000000-0000-0000-0000-000000007779",
  "Authorization": "Bearer <token>"
]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/v1/sandboxes/sbx_0000be20/exec")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### `sleep 5` with timeout_seconds 1, on Daytona

**Response**

```json
{
  "exit_code": 143,
  "stdout": "",
  "stderr": "",
  "timed_out": true
}
```

**SDK Code**

```python `sleep 5` with timeout_seconds 1, on Daytona
import requests

url = "https://api.example.com/v1/sandboxes/sbx_0000be20/exec"

headers = {
    "Idempotency-Key": "00000000-0000-0000-0000-000000007779",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript `sleep 5` with timeout_seconds 1, on Daytona
const url = 'https://api.example.com/v1/sandboxes/sbx_0000be20/exec';
const options = {
  method: 'POST',
  headers: {
    'Idempotency-Key': '00000000-0000-0000-0000-000000007779',
    Authorization: 'Bearer <token>'
  }
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go `sleep 5` with timeout_seconds 1, on Daytona
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.example.com/v1/sandboxes/sbx_0000be20/exec"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("Idempotency-Key", "00000000-0000-0000-0000-000000007779")
	req.Header.Add("Authorization", "Bearer <token>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby `sleep 5` with timeout_seconds 1, on Daytona
require 'uri'
require 'net/http'

url = URI("https://api.example.com/v1/sandboxes/sbx_0000be20/exec")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '00000000-0000-0000-0000-000000007779'
request["Authorization"] = 'Bearer <token>'

response = http.request(request)
puts response.read_body
```

```java `sleep 5` with timeout_seconds 1, on Daytona
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.example.com/v1/sandboxes/sbx_0000be20/exec")
  .header("Idempotency-Key", "00000000-0000-0000-0000-000000007779")
  .header("Authorization", "Bearer <token>")
  .asString();
```

```php `sleep 5` with timeout_seconds 1, on Daytona
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.example.com/v1/sandboxes/sbx_0000be20/exec', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Idempotency-Key' => '00000000-0000-0000-0000-000000007779',
  ],
]);

echo $response->getBody();
```

```csharp `sleep 5` with timeout_seconds 1, on Daytona
using RestSharp;

var client = new RestClient("https://api.example.com/v1/sandboxes/sbx_0000be20/exec");
var request = new RestRequest(Method.POST);
request.AddHeader("Idempotency-Key", "00000000-0000-0000-0000-000000007779");
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift `sleep 5` with timeout_seconds 1, on Daytona
import Foundation

let headers = [
  "Idempotency-Key": "00000000-0000-0000-0000-000000007779",
  "Authorization": "Bearer <token>"
]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/v1/sandboxes/sbx_0000be20/exec")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### started

**Response**

```json
{
  "exit_code": null,
  "stdout": "",
  "stderr": "",
  "finished_at": null,
  "id": "exec_0000e1b1",
  "started_at": "2026-11-23T22:20:50.758Z",
  "status": "running",
  "stderr_offset": 0,
  "stdout_offset": 0
}
```

**SDK Code**

```python started
import requests

url = "https://api.example.com/v1/sandboxes/sbx_0000be20/exec"

headers = {
    "Idempotency-Key": "00000000-0000-0000-0000-000000007779",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript started
const url = 'https://api.example.com/v1/sandboxes/sbx_0000be20/exec';
const options = {
  method: 'POST',
  headers: {
    'Idempotency-Key': '00000000-0000-0000-0000-000000007779',
    Authorization: 'Bearer <token>'
  }
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go started
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.example.com/v1/sandboxes/sbx_0000be20/exec"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("Idempotency-Key", "00000000-0000-0000-0000-000000007779")
	req.Header.Add("Authorization", "Bearer <token>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby started
require 'uri'
require 'net/http'

url = URI("https://api.example.com/v1/sandboxes/sbx_0000be20/exec")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '00000000-0000-0000-0000-000000007779'
request["Authorization"] = 'Bearer <token>'

response = http.request(request)
puts response.read_body
```

```java started
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.example.com/v1/sandboxes/sbx_0000be20/exec")
  .header("Idempotency-Key", "00000000-0000-0000-0000-000000007779")
  .header("Authorization", "Bearer <token>")
  .asString();
```

```php started
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.example.com/v1/sandboxes/sbx_0000be20/exec', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Idempotency-Key' => '00000000-0000-0000-0000-000000007779',
  ],
]);

echo $response->getBody();
```

```csharp started
using RestSharp;

var client = new RestClient("https://api.example.com/v1/sandboxes/sbx_0000be20/exec");
var request = new RestRequest(Method.POST);
request.AddHeader("Idempotency-Key", "00000000-0000-0000-0000-000000007779");
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift started
import Foundation

let headers = [
  "Idempotency-Key": "00000000-0000-0000-0000-000000007779",
  "Authorization": "Bearer <token>"
]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/v1/sandboxes/sbx_0000be20/exec")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Foreground, a shell command with cwd and env

**Request**

```json
{
  "command": "echo $GREETING from $(whoami) in $(pwd); echo oops >&2; exit 3",
  "cwd": "/tmp",
  "env": {
    "GREETING": "hi"
  }
}
```

**Response**

```json
{
  "exit_code": 3,
  "stdout": "hi from root in /tmp\n",
  "stderr": "oops\n",
  "timed_out": false
}
```

**SDK Code**

```python Foreground, a shell command with cwd and env
import requests

url = "https://api.example.com/v1/sandboxes/sbx_0000be20/exec"

payload = {
    "command": "echo $GREETING from $(whoami) in $(pwd); echo oops >&2; exit 3",
    "cwd": "/tmp",
    "env": { "GREETING": "hi" }
}
headers = {
    "Idempotency-Key": "00000000-0000-0000-0000-000000007779",
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Foreground, a shell command with cwd and env
const url = 'https://api.example.com/v1/sandboxes/sbx_0000be20/exec';
const options = {
  method: 'POST',
  headers: {
    'Idempotency-Key': '00000000-0000-0000-0000-000000007779',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: '{"command":"echo $GREETING from $(whoami) in $(pwd); echo oops >&2; exit 3","cwd":"/tmp","env":{"GREETING":"hi"}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Foreground, a shell command with cwd and env
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.example.com/v1/sandboxes/sbx_0000be20/exec"

	payload := strings.NewReader("{\n  \"command\": \"echo $GREETING from $(whoami) in $(pwd); echo oops >&2; exit 3\",\n  \"cwd\": \"/tmp\",\n  \"env\": {\n    \"GREETING\": \"hi\"\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Idempotency-Key", "00000000-0000-0000-0000-000000007779")
	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Foreground, a shell command with cwd and env
require 'uri'
require 'net/http'

url = URI("https://api.example.com/v1/sandboxes/sbx_0000be20/exec")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '00000000-0000-0000-0000-000000007779'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"command\": \"echo $GREETING from $(whoami) in $(pwd); echo oops >&2; exit 3\",\n  \"cwd\": \"/tmp\",\n  \"env\": {\n    \"GREETING\": \"hi\"\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java Foreground, a shell command with cwd and env
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.example.com/v1/sandboxes/sbx_0000be20/exec")
  .header("Idempotency-Key", "00000000-0000-0000-0000-000000007779")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"command\": \"echo $GREETING from $(whoami) in $(pwd); echo oops >&2; exit 3\",\n  \"cwd\": \"/tmp\",\n  \"env\": {\n    \"GREETING\": \"hi\"\n  }\n}")
  .asString();
```

```php Foreground, a shell command with cwd and env
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.example.com/v1/sandboxes/sbx_0000be20/exec', [
  'body' => '{
  "command": "echo $GREETING from $(whoami) in $(pwd); echo oops >&2; exit 3",
  "cwd": "/tmp",
  "env": {
    "GREETING": "hi"
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
    'Idempotency-Key' => '00000000-0000-0000-0000-000000007779',
  ],
]);

echo $response->getBody();
```

```csharp Foreground, a shell command with cwd and env
using RestSharp;

var client = new RestClient("https://api.example.com/v1/sandboxes/sbx_0000be20/exec");
var request = new RestRequest(Method.POST);
request.AddHeader("Idempotency-Key", "00000000-0000-0000-0000-000000007779");
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"command\": \"echo $GREETING from $(whoami) in $(pwd); echo oops >&2; exit 3\",\n  \"cwd\": \"/tmp\",\n  \"env\": {\n    \"GREETING\": \"hi\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Foreground, a shell command with cwd and env
import Foundation

let headers = [
  "Idempotency-Key": "00000000-0000-0000-0000-000000007779",
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "command": "echo $GREETING from $(whoami) in $(pwd); echo oops >&2; exit 3",
  "cwd": "/tmp",
  "env": ["GREETING": "hi"]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/v1/sandboxes/sbx_0000be20/exec")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Foreground, an argument list

**Request**

```json
{
  "command": [
    "python3",
    "-c",
    "print(6*7)"
  ],
  "timeout_seconds": 30
}
```

**Response**

```json
{
  "exit_code": 3,
  "stdout": "hi from root in /tmp\n",
  "stderr": "oops\n",
  "timed_out": false
}
```

**SDK Code**

```python Foreground, an argument list
import requests

url = "https://api.example.com/v1/sandboxes/sbx_0000be20/exec"

payload = {
    "command": ["python3", "-c", "print(6*7)"],
    "timeout_seconds": 30
}
headers = {
    "Idempotency-Key": "00000000-0000-0000-0000-000000007779",
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Foreground, an argument list
const url = 'https://api.example.com/v1/sandboxes/sbx_0000be20/exec';
const options = {
  method: 'POST',
  headers: {
    'Idempotency-Key': '00000000-0000-0000-0000-000000007779',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: '{"command":["python3","-c","print(6*7)"],"timeout_seconds":30}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Foreground, an argument list
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.example.com/v1/sandboxes/sbx_0000be20/exec"

	payload := strings.NewReader("{\n  \"command\": [\n    \"python3\",\n    \"-c\",\n    \"print(6*7)\"\n  ],\n  \"timeout_seconds\": 30\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Idempotency-Key", "00000000-0000-0000-0000-000000007779")
	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Foreground, an argument list
require 'uri'
require 'net/http'

url = URI("https://api.example.com/v1/sandboxes/sbx_0000be20/exec")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '00000000-0000-0000-0000-000000007779'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"command\": [\n    \"python3\",\n    \"-c\",\n    \"print(6*7)\"\n  ],\n  \"timeout_seconds\": 30\n}"

response = http.request(request)
puts response.read_body
```

```java Foreground, an argument list
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.example.com/v1/sandboxes/sbx_0000be20/exec")
  .header("Idempotency-Key", "00000000-0000-0000-0000-000000007779")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"command\": [\n    \"python3\",\n    \"-c\",\n    \"print(6*7)\"\n  ],\n  \"timeout_seconds\": 30\n}")
  .asString();
```

```php Foreground, an argument list
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.example.com/v1/sandboxes/sbx_0000be20/exec', [
  'body' => '{
  "command": [
    "python3",
    "-c",
    "print(6*7)"
  ],
  "timeout_seconds": 30
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
    'Idempotency-Key' => '00000000-0000-0000-0000-000000007779',
  ],
]);

echo $response->getBody();
```

```csharp Foreground, an argument list
using RestSharp;

var client = new RestClient("https://api.example.com/v1/sandboxes/sbx_0000be20/exec");
var request = new RestRequest(Method.POST);
request.AddHeader("Idempotency-Key", "00000000-0000-0000-0000-000000007779");
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"command\": [\n    \"python3\",\n    \"-c\",\n    \"print(6*7)\"\n  ],\n  \"timeout_seconds\": 30\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Foreground, an argument list
import Foundation

let headers = [
  "Idempotency-Key": "00000000-0000-0000-0000-000000007779",
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "command": ["python3", "-c", "print(6*7)"],
  "timeout_seconds": 30
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/v1/sandboxes/sbx_0000be20/exec")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Stream the output

**Request**

```json
{
  "command": "for i in 1 2 3; do echo line $i; sleep 0.3; done; echo warn >&2; exit 2",
  "stream": true
}
```

**Response**

```json
{
  "exit_code": 3,
  "stdout": "hi from root in /tmp\n",
  "stderr": "oops\n",
  "timed_out": false
}
```

**SDK Code**

```python Stream the output
import requests

url = "https://api.example.com/v1/sandboxes/sbx_0000be20/exec"

payload = {
    "command": "for i in 1 2 3; do echo line $i; sleep 0.3; done; echo warn >&2; exit 2",
    "stream": True
}
headers = {
    "Idempotency-Key": "00000000-0000-0000-0000-000000007779",
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Stream the output
const url = 'https://api.example.com/v1/sandboxes/sbx_0000be20/exec';
const options = {
  method: 'POST',
  headers: {
    'Idempotency-Key': '00000000-0000-0000-0000-000000007779',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: '{"command":"for i in 1 2 3; do echo line $i; sleep 0.3; done; echo warn >&2; exit 2","stream":true}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Stream the output
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.example.com/v1/sandboxes/sbx_0000be20/exec"

	payload := strings.NewReader("{\n  \"command\": \"for i in 1 2 3; do echo line $i; sleep 0.3; done; echo warn >&2; exit 2\",\n  \"stream\": true\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Idempotency-Key", "00000000-0000-0000-0000-000000007779")
	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Stream the output
require 'uri'
require 'net/http'

url = URI("https://api.example.com/v1/sandboxes/sbx_0000be20/exec")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '00000000-0000-0000-0000-000000007779'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"command\": \"for i in 1 2 3; do echo line $i; sleep 0.3; done; echo warn >&2; exit 2\",\n  \"stream\": true\n}"

response = http.request(request)
puts response.read_body
```

```java Stream the output
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.example.com/v1/sandboxes/sbx_0000be20/exec")
  .header("Idempotency-Key", "00000000-0000-0000-0000-000000007779")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"command\": \"for i in 1 2 3; do echo line $i; sleep 0.3; done; echo warn >&2; exit 2\",\n  \"stream\": true\n}")
  .asString();
```

```php Stream the output
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.example.com/v1/sandboxes/sbx_0000be20/exec', [
  'body' => '{
  "command": "for i in 1 2 3; do echo line $i; sleep 0.3; done; echo warn >&2; exit 2",
  "stream": true
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
    'Idempotency-Key' => '00000000-0000-0000-0000-000000007779',
  ],
]);

echo $response->getBody();
```

```csharp Stream the output
using RestSharp;

var client = new RestClient("https://api.example.com/v1/sandboxes/sbx_0000be20/exec");
var request = new RestRequest(Method.POST);
request.AddHeader("Idempotency-Key", "00000000-0000-0000-0000-000000007779");
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"command\": \"for i in 1 2 3; do echo line $i; sleep 0.3; done; echo warn >&2; exit 2\",\n  \"stream\": true\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Stream the output
import Foundation

let headers = [
  "Idempotency-Key": "00000000-0000-0000-0000-000000007779",
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "command": "for i in 1 2 3; do echo line $i; sleep 0.3; done; echo warn >&2; exit 2",
  "stream": true
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/v1/sandboxes/sbx_0000be20/exec")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Start in the background (send Idempotency-Key with it)

**Request**

```json
{
  "command": "for i in 1 2 3 4 5 6; do echo tick $i; sleep 1; done; echo done",
  "timeout_seconds": 120,
  "background": true
}
```

**Response**

```json
{
  "exit_code": 3,
  "stdout": "hi from root in /tmp\n",
  "stderr": "oops\n",
  "timed_out": false
}
```

**SDK Code**

```python Start in the background (send Idempotency-Key with it)
import requests

url = "https://api.example.com/v1/sandboxes/sbx_0000be20/exec"

payload = {
    "command": "for i in 1 2 3 4 5 6; do echo tick $i; sleep 1; done; echo done",
    "timeout_seconds": 120,
    "background": True
}
headers = {
    "Idempotency-Key": "00000000-0000-0000-0000-000000007779",
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Start in the background (send Idempotency-Key with it)
const url = 'https://api.example.com/v1/sandboxes/sbx_0000be20/exec';
const options = {
  method: 'POST',
  headers: {
    'Idempotency-Key': '00000000-0000-0000-0000-000000007779',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: '{"command":"for i in 1 2 3 4 5 6; do echo tick $i; sleep 1; done; echo done","timeout_seconds":120,"background":true}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Start in the background (send Idempotency-Key with it)
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.example.com/v1/sandboxes/sbx_0000be20/exec"

	payload := strings.NewReader("{\n  \"command\": \"for i in 1 2 3 4 5 6; do echo tick $i; sleep 1; done; echo done\",\n  \"timeout_seconds\": 120,\n  \"background\": true\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Idempotency-Key", "00000000-0000-0000-0000-000000007779")
	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Start in the background (send Idempotency-Key with it)
require 'uri'
require 'net/http'

url = URI("https://api.example.com/v1/sandboxes/sbx_0000be20/exec")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '00000000-0000-0000-0000-000000007779'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"command\": \"for i in 1 2 3 4 5 6; do echo tick $i; sleep 1; done; echo done\",\n  \"timeout_seconds\": 120,\n  \"background\": true\n}"

response = http.request(request)
puts response.read_body
```

```java Start in the background (send Idempotency-Key with it)
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.example.com/v1/sandboxes/sbx_0000be20/exec")
  .header("Idempotency-Key", "00000000-0000-0000-0000-000000007779")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"command\": \"for i in 1 2 3 4 5 6; do echo tick $i; sleep 1; done; echo done\",\n  \"timeout_seconds\": 120,\n  \"background\": true\n}")
  .asString();
```

```php Start in the background (send Idempotency-Key with it)
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.example.com/v1/sandboxes/sbx_0000be20/exec', [
  'body' => '{
  "command": "for i in 1 2 3 4 5 6; do echo tick $i; sleep 1; done; echo done",
  "timeout_seconds": 120,
  "background": true
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
    'Idempotency-Key' => '00000000-0000-0000-0000-000000007779',
  ],
]);

echo $response->getBody();
```

```csharp Start in the background (send Idempotency-Key with it)
using RestSharp;

var client = new RestClient("https://api.example.com/v1/sandboxes/sbx_0000be20/exec");
var request = new RestRequest(Method.POST);
request.AddHeader("Idempotency-Key", "00000000-0000-0000-0000-000000007779");
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"command\": \"for i in 1 2 3 4 5 6; do echo tick $i; sleep 1; done; echo done\",\n  \"timeout_seconds\": 120,\n  \"background\": true\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Start in the background (send Idempotency-Key with it)
import Foundation

let headers = [
  "Idempotency-Key": "00000000-0000-0000-0000-000000007779",
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "command": "for i in 1 2 3 4 5 6; do echo tick $i; sleep 1; done; echo done",
  "timeout_seconds": 120,
  "background": true
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/v1/sandboxes/sbx_0000be20/exec")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Start in the background with stdin kept open

**Request**

```json
{
  "command": [
    "python3",
    "-u",
    "-c",
    "import sys\nfor line in sys.stdin:\n    print('got', line.strip())"
  ],
  "background": true,
  "stdin": true
}
```

**Response**

```json
{
  "exit_code": 3,
  "stdout": "hi from root in /tmp\n",
  "stderr": "oops\n",
  "timed_out": false
}
```

**SDK Code**

```python Start in the background with stdin kept open
import requests

url = "https://api.example.com/v1/sandboxes/sbx_0000be20/exec"

payload = {
    "command": ["python3", "-u", "-c", "import sys
for line in sys.stdin:
    print('got', line.strip())"],
    "background": True,
    "stdin": True
}
headers = {
    "Idempotency-Key": "00000000-0000-0000-0000-000000007779",
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Start in the background with stdin kept open
const url = 'https://api.example.com/v1/sandboxes/sbx_0000be20/exec';
const options = {
  method: 'POST',
  headers: {
    'Idempotency-Key': '00000000-0000-0000-0000-000000007779',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: '{"command":["python3","-u","-c","import sys\nfor line in sys.stdin:\n    print(\'got\', line.strip())"],"background":true,"stdin":true}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Start in the background with stdin kept open
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.example.com/v1/sandboxes/sbx_0000be20/exec"

	payload := strings.NewReader("{\n  \"command\": [\n    \"python3\",\n    \"-u\",\n    \"-c\",\n    \"import sys\\nfor line in sys.stdin:\\n    print('got', line.strip())\"\n  ],\n  \"background\": true,\n  \"stdin\": true\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Idempotency-Key", "00000000-0000-0000-0000-000000007779")
	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Start in the background with stdin kept open
require 'uri'
require 'net/http'

url = URI("https://api.example.com/v1/sandboxes/sbx_0000be20/exec")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '00000000-0000-0000-0000-000000007779'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"command\": [\n    \"python3\",\n    \"-u\",\n    \"-c\",\n    \"import sys\\nfor line in sys.stdin:\\n    print('got', line.strip())\"\n  ],\n  \"background\": true,\n  \"stdin\": true\n}"

response = http.request(request)
puts response.read_body
```

```java Start in the background with stdin kept open
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.example.com/v1/sandboxes/sbx_0000be20/exec")
  .header("Idempotency-Key", "00000000-0000-0000-0000-000000007779")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"command\": [\n    \"python3\",\n    \"-u\",\n    \"-c\",\n    \"import sys\\nfor line in sys.stdin:\\n    print('got', line.strip())\"\n  ],\n  \"background\": true,\n  \"stdin\": true\n}")
  .asString();
```

```php Start in the background with stdin kept open
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.example.com/v1/sandboxes/sbx_0000be20/exec', [
  'body' => '{
  "command": [
    "python3",
    "-u",
    "-c",
    "import sys\\nfor line in sys.stdin:\\n    print(\'got\', line.strip())"
  ],
  "background": true,
  "stdin": true
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
    'Idempotency-Key' => '00000000-0000-0000-0000-000000007779',
  ],
]);

echo $response->getBody();
```

```csharp Start in the background with stdin kept open
using RestSharp;

var client = new RestClient("https://api.example.com/v1/sandboxes/sbx_0000be20/exec");
var request = new RestRequest(Method.POST);
request.AddHeader("Idempotency-Key", "00000000-0000-0000-0000-000000007779");
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"command\": [\n    \"python3\",\n    \"-u\",\n    \"-c\",\n    \"import sys\\nfor line in sys.stdin:\\n    print('got', line.strip())\"\n  ],\n  \"background\": true,\n  \"stdin\": true\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Start in the background with stdin kept open
import Foundation

let headers = [
  "Idempotency-Key": "00000000-0000-0000-0000-000000007779",
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "command": ["python3", "-u", "-c", "import sys
for line in sys.stdin:
    print('got', line.strip())"],
  "background": true,
  "stdin": true
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/v1/sandboxes/sbx_0000be20/exec")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```