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

# Run a command over a WebSocket

> Runs a command over a WebSocket, streaming output back and accepting
stdin over one connection.

Connect with two `Sec-WebSocket-Protocol` values: `superserve.exec.v1`
and `token.<access-token>`.

I/O rides binary frames prefixed with a one-byte channel, so output is
byte-exact; lifecycle and control ride text JSON frames.

- First frame (text): an `ExecRequest` JSON object. Omitting `timeout_s`
  runs with no per-command timeout.
- Client frames: a binary frame is stdin, prefixed with channel `0x00`
  (`[0x00][bytes]`); a text frame is JSON control —
  `{"type":"stdin_close"}` or `{"type":"signal","name":"SIGINT"}`.
  Frames are capped at 64 KiB, so chunk larger stdin.
- Server frames: a binary frame is output, prefixed with its channel
  (`0x01` stdout, `0x02` stderr); a text frame is JSON lifecycle —
  `{"exit_code":N,"finished":true}`, or `{"error":"...","code":"..."}`.
  Closes on exit.




## OpenAPI

````yaml https://raw.githubusercontent.com/superserve-ai/sandbox/refs/heads/main/api/openapi.yaml get /exec/connect
openapi: 3.1.0
info:
  title: Superserve API
  version: 0.1.0
  description: >
    Superserve provides sandbox infrastructure to run AI agents in the cloud.
    Powered by Firecracker MicroVMs.


    ## Sandbox lifecycle


    ```

    active <--> paused --> deleted

    ```


    A sandbox is `active` when running and `paused` after being paused. Resuming

    a paused sandbox returns it to `active`. Deleting releases all resources.


    | Endpoint | What it does |

    |----------|-------------|

    | `POST /sandboxes` | Create a new sandbox (optionally `from_template`) |

    | `PATCH /sandboxes/:id` | Partially update a running sandbox (e.g. network
    rules) |

    | `POST /sandboxes/:id/pause` | Snapshot full state, suspend the VM |

    | `POST /sandboxes/:id/resume` | Restore from snapshot, continue where it
    left off |

    | `DELETE /sandboxes/:id` | Delete sandbox and all resources |


    ## Sandbox environment


    By default sandboxes boot from the curated `superserve/base` template
    (Ubuntu 24.04,

    1 vCPU, 1 GB RAM, 4 GB disk, with Python 3.12, Node.js 22, npm, git, curl,

    and build-essential pre-installed). Callers can override with any template

    name (e.g. `superserve/python-3.11`, `superserve/node-22`) or a team-owned
    template UUID

    via the `from_template` field on `POST /sandboxes`.


    ## Files and commands


    `/files`, `/exec`, and `/exec/stream` run against a single sandbox and use

    its `X-Access-Token` (returned by create, resume, and activate), not the

    team API key. Two host forms reach them:


    - `https://sandbox.superserve.ai/...` with `X-Superserve-Sandbox-Id:
    <sandbox_id>`.

    - `https://boxd-{sandbox_id}.sandbox.superserve.ai/...` — no routing header
    needed.
  contact:
    name: Superserve Team
  license:
    name: Proprietary
servers:
  - url: https://api.superserve.ai
    description: Production
security: []
paths:
  /exec/connect:
    servers:
      - url: https://sandbox.superserve.ai
        description: Shared host — send the sandbox ID in `X-Superserve-Sandbox-Id`.
      - url: https://boxd-{sandbox_id}.sandbox.superserve.ai
        description: Per-sandbox host.
        variables:
          sandbox_id:
            default: ''
            description: The sandbox ID.
    get:
      tags:
        - Exec
      summary: Run a command over a WebSocket
      description: |
        Runs a command over a WebSocket, streaming output back and accepting
        stdin over one connection.

        Connect with two `Sec-WebSocket-Protocol` values: `superserve.exec.v1`
        and `token.<access-token>`.

        I/O rides binary frames prefixed with a one-byte channel, so output is
        byte-exact; lifecycle and control ride text JSON frames.

        - First frame (text): an `ExecRequest` JSON object. Omitting `timeout_s`
          runs with no per-command timeout.
        - Client frames: a binary frame is stdin, prefixed with channel `0x00`
          (`[0x00][bytes]`); a text frame is JSON control —
          `{"type":"stdin_close"}` or `{"type":"signal","name":"SIGINT"}`.
          Frames are capped at 64 KiB, so chunk larger stdin.
        - Server frames: a binary frame is output, prefixed with its channel
          (`0x01` stdout, `0x02` stderr); a text frame is JSON lifecycle —
          `{"exit_code":N,"finished":true}`, or `{"error":"...","code":"..."}`.
          Closes on exit.
      operationId: execConnect
      responses:
        '101':
          description: Switching Protocols — the WebSocket is established.

````