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

# Main Command

A sandbox created with a [`command`](https://developers.telnyx.com/docs/edge-compute/sandboxes/composition#main-command) runs one more process, its main command, which is not an exec. Its stdin, its exit, and its logs have their own routes on the data plane.

## Attach

`GET /sandbox/{id}/attach` is a WebSocket to the main command's stdin. Stdin goes in over it as `stdin` messages, as on an [exec's attach](https://developers.telnyx.com/docs/edge-compute/sandboxes/data-plane-operations/execs.md#client-messages). The socket carries no output, so it is silent until its first `heartbeat` at 30 seconds. Its final message carries the exit code, and is sent again to a later attach. Output is read through the [logs](#logs).

## Stdin

`POST /sandbox/{id}/stdin/close` sends end-of-file to the main command's stdin.

`/attach` and `/stdin/close` are refused with `409 no_command` on a sandbox without a main command.

## Logs

`GET /sandbox/{id}/logs` returns the main command's output as lines, oldest first, 20 per page and at most 100.

```json Output theme={null}
{
  "data": [
    {
      "type": "line",
      "ts": "2026-11-11T19:04:06.120Z",
      "line": "Listening on :3000",
      "position": "1",
      ...
    }
  ],
  "meta": { "next_page_after": "1", "page_size": 20 }
}
```

`page[after]` continues from a `position`. A sandbox without a main command has no log lines. `stream` is `null` on every line, and `?stream=` is refused with `400`, because the main command's output does not tell stdout and stderr apart.

### Follow

`?follow=true` streams new lines as server-sent events. Each line is an `event: log` whose `id` is its position. A `Last-Event-ID` header resumes after that position. On a line that `follow=true` replays, `ts` is the time of the read. A comment is sent every 30 seconds, and an `event: end` marks the end of the logs once the sandbox has terminated.

```bash API theme={null}
curl -N "$DATA_API/$SANDBOX_ID/logs?follow=true" \
  -H "Authorization: Bearer $SANDBOX_TOKEN"
```

```text Output theme={null}
event: log
id: 1
data: {"type":"line","ts":"2026-11-11T19:04:06.120Z","line":"Listening on :3000","position":"1"}
```

The host keeps 64 MiB of logs per sandbox. A line longer than 256 KiB is split.
