> ## 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.

# Run a command in a sandbox

> Starts a command inside a running sandbox and returns the exec at once: `running`, or `exited` with its `exit_code` if it already finished. It doesn't wait for the command or stream its output: attach to the exec's WebSocket for its output and stdin, or wait for the exit code with `GET /ai/sandboxes/{sandbox_id}/execs/{exec_id}?wait=…`.

If the sandbox can't confirm the start within a few seconds (it may still be starting up), the exec comes back `starting`, and the start completes in the background: follow it with `GET /ai/sandboxes/{sandbox_id}/execs/{exec_id}`. A start that can't be confirmed within 5 minutes ends `failed` with reason `agent_unavailable`.

The process keeps running when you disconnect. It uses the sandbox's working directory and environment unless you override them.

Send an `Idempotency-Key`: a retry with the same key returns the same exec instead of starting the command twice, and completes a start that was still `starting`.



## OpenAPI

````yaml /openapi/source/external/sandboxes/sandboxes.json post /ai/sandboxes/{sandbox_id}/execs
openapi: 3.1.0
info:
  title: Telnyx API
  version: 1.0.0
  description: >-
    Run a container image of your choice on a whole GPU node, each sandbox in
    its own virtual machine, for seconds or indefinitely. Run commands inside
    it, move files in and out, stream its logs, read its metrics, and pay per
    second while it runs.


    ## Preview


    GPU Sandboxes is in an invite-only preview. `GET /ai/sandbox-access` tells
    whether it is enabled for your organization.


    ## Authentication


    All endpoints require a Telnyx API key sent as a Bearer token in the
    `Authorization` header.


    ## Retries


    Every side-effecting endpoint accepts an `Idempotency-Key` header. Send one
    on `POST /ai/sandboxes` and `POST /ai/sandboxes/{sandbox_id}/execs`, so a
    retry after a lost response doesn't start (and bill) a second workload.


    ## Errors


    Errors use the standard Telnyx error body. General errors carry their
    5-digit `code` (e.g. `10009`); Sandboxes-specific errors are identified by
    their name in `title` (e.g. `quota_exceeded`).
  contact:
    email: support@telnyx.com
  x-latency-category: responsive
  x-endpoint-cost: light
servers:
  - url: https://api.telnyx.com/v2
    description: Telnyx API v2
security:
  - bearerAuth: []
tags:
  - name: Sandboxes
    description: >-
      Create, find, wait for, tag and terminate sandboxes, and close the main
      process's stdin.
  - name: Sandbox execs
    description: Run commands in a running sandbox.
  - name: Sandbox files
    description: Read, write, list and delete files inside a running sandbox.
  - name: Sandbox logs
    description: The main process's stored and live output.
  - name: Sandbox metrics
    description: CPU, network, memory, disk and GPU usage.
  - name: Sandbox GPU types
    description: What you can rent, and at what price.
  - name: Sandbox access
    description: Whether Sandboxes is enabled for your organization.
paths:
  /ai/sandboxes/{sandbox_id}/execs:
    post:
      tags:
        - Sandbox execs
      summary: Run a command in a sandbox
      description: >-
        Starts a command inside a running sandbox and returns the exec at once:
        `running`, or `exited` with its `exit_code` if it already finished. It
        doesn't wait for the command or stream its output: attach to the exec's
        WebSocket for its output and stdin, or wait for the exit code with `GET
        /ai/sandboxes/{sandbox_id}/execs/{exec_id}?wait=…`.


        If the sandbox can't confirm the start within a few seconds (it may
        still be starting up), the exec comes back `starting`, and the start
        completes in the background: follow it with `GET
        /ai/sandboxes/{sandbox_id}/execs/{exec_id}`. A start that can't be
        confirmed within 5 minutes ends `failed` with reason
        `agent_unavailable`.


        The process keeps running when you disconnect. It uses the sandbox's
        working directory and environment unless you override them.


        Send an `Idempotency-Key`: a retry with the same key returns the same
        exec instead of starting the command twice, and completes a start that
        was still `starting`.
      operationId: CreateSandboxExec
      parameters:
        - description: Sandbox ID (`sb-…`).
          in: path
          name: sandbox_id
          required: true
          schema:
            maxLength: 64
            minLength: 1
            type: string
          example: sb-0192f1c2-7a4b-7c3e-9d1e-2f3a4b5c6d7e
        - description: >-
            Optional client-chosen key (e.g. a UUID, at most 255 characters)
            that makes the call safe to retry. Within 24 h, the same key with
            the same request returns the stored response instead of acting
            twice; the same key with a different request fails with
            `idempotency_key_reused`; a request with a key that's still being
            processed fails with `request_in_progress`.
          in: header
          name: Idempotency-Key
          required: false
          schema:
            maxLength: 255
            minLength: 1
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExecCreateReq'
            example:
              command:
                - python
                - evaluate.py
                - '--split'
                - test
              env:
                LOG_LEVEL: info
              workdir: /app
              timeout: 3600
      responses:
        '201':
          description: The exec.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExecRespData'
              example:
                data:
                  id: exec-0192f1c9-3e2a-7b1d-8c4f-5a6b7c8d9e0f
                  sandbox_id: sb-0192f1c2-7a4b-7c3e-9d1e-2f3a4b5c6d7e
                  command:
                    - python
                    - evaluate.py
                    - '--split'
                    - test
                  env:
                    LOG_LEVEL: info
                  workdir: /app
                  timeout: 3600
                  status: running
                  exit_code: null
                  reason: null
                  created_at: '2026-11-13T10:05:00Z'
                  finished_at: null
        '400':
          description: >-
            Validation error: the standard Telnyx validation errors (codes such
            as 10004 missing parameter, 10015 bad request, 10025 invalid string
            length, 10026 invalid type).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: '10015'
                    title: Bad Request
                    detail: Input should be greater than or equal to 1.
                    source:
                      pointer: /timeout
        '401':
          description: Missing or invalid API key (code 10009).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: '10009'
                    title: Authentication failed
                    detail: Could not find any usable credentials in the request.
        '403':
          description: >-
            - `sandboxes_require_verification`: your account isn't fully
            verified.

            - `sandboxes_not_whitelisted`: Sandboxes isn't enabled for your
            organization (invite-only preview); `GET /ai/sandbox-access` tells
            whether it is.

            - `sandboxes_disabled`: creating sandboxes, starting execs or
            completing an exec's start is disabled for your organization; other
            operations keep working.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - title: sandboxes_not_whitelisted
                    detail: The organization isn't whitelisted.
        '404':
          description: >-
            Not found (code 10005): the resource doesn't exist or belongs to
            another organization. The detail says what's missing.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: '10005'
                    title: Resource not found
                    detail: Sandbox not found.
        '409':
          description: >-
            - `request_in_progress`: a request with the same `Idempotency-Key`
            is still being processed; retry later.

            - `sandbox_not_running`: the operation needs a running sandbox.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - title: sandbox_not_running
                    detail: The sandbox isn't running.
        '422':
          description: >-
            - `idempotency_key_reused`: the same `Idempotency-Key` was sent with
            a different request.

            - `invalid_command`: the argv breaks a size rule: at most 4096
            arguments, each at most 131071 bytes in UTF-8, at most 1 MiB in
            total, and no NUL byte.

            - `invalid_env`: an `env` name isn't a POSIX name, uses the reserved
            `TELNYX_SANDBOX_` prefix, or a size limit is exceeded.

            - `invalid_workdir`: `workdir` isn't an absolute path.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - title: invalid_command
                    detail: The command has more than 4096 arguments.
        '503':
          description: A dependency can't answer right now (code 10037); retry later.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: '10037'
                    title: Service unavailable
                    detail: A dependency can't answer right now; retry later.
components:
  schemas:
    ExecCreateReq:
      additionalProperties: false
      description: A command to run in a running sandbox.
      properties:
        command:
          description: >-
            Argv to run, e.g. `["python", "train.py"]`: at most 4096 arguments,
            each at most 131071 bytes in UTF-8, at most 1 MiB in total, with no
            NUL byte (else `invalid_command`).
          items:
            type: string
          minItems: 1
          type: array
          maxItems: 4096
        env:
          additionalProperties:
            type: string
            maxLength: 32768
          description: >-
            Extra environment variables on top of the sandbox's environment.
            Same rules as on create: POSIX names, no `TELNYX_SANDBOX_` prefix,
            size limits (else `invalid_env`).
          type: object
          maxProperties: 256
          propertyNames:
            pattern: ^(?!TELNYX_SANDBOX_)[A-Za-z_][A-Za-z0-9_]*$
        timeout:
          description: >-
            Stop the process after this many seconds (status `terminated`,
            reason `timeout`). Default: no limit. At most 2147483647 (about 68
            years); it never outlives the sandbox.
          maximum: 2147483647
          minimum: 1
          type:
            - integer
            - 'null'
        workdir:
          description: >-
            Absolute working directory (else `invalid_workdir`). Defaults to the
            sandbox's working directory.
          type:
            - string
            - 'null'
          pattern: ^/
          maxLength: 4096
      required:
        - command
      type: object
    ExecRespData:
      properties:
        data:
          $ref: '#/components/schemas/Exec'
      required:
        - data
      type: object
    TelnyxErrors:
      description: The standard Telnyx error body.
      properties:
        errors:
          description: One or more errors.
          items:
            $ref: '#/components/schemas/TelnyxError'
          type: array
      required:
        - errors
      type: object
    Exec:
      description: >-
        A process started in a sandbox. It keeps running when clients
        disconnect. Execs live as long as their sandbox.
      properties:
        command:
          description: Argv.
          items:
            type: string
          type: array
        created_at:
          description: When it was started.
          format: date-time
          type: string
        env:
          additionalProperties:
            type: string
          description: The extra environment variables given.
          type: object
        exit_code:
          description: >-
            Set once `exited`. A process killed by a signal reports 128 + the
            signal number (e.g. 137 for SIGKILL).
          type:
            - integer
            - 'null'
        finished_at:
          description: When it ended.
          format: date-time
          type:
            - string
            - 'null'
        id:
          description: Exec ID (`exec-…`).
          type: string
        reason:
          description: Set when `failed` or `terminated`.
          anyOf:
            - $ref: '#/components/schemas/ExecReason'
            - type: 'null'
        sandbox_id:
          description: The sandbox it runs in.
          type: string
        status:
          $ref: '#/components/schemas/ExecStatus'
        timeout:
          description: Exec timeout in seconds, if set.
          type:
            - integer
            - 'null'
        workdir:
          description: >-
            Working directory: the one given, else the sandbox's. `null` when
            neither is known: the sandbox was created without `workdir` and its
            image's wasn't read.
          type:
            - string
            - 'null'
      required:
        - id
        - sandbox_id
        - command
        - workdir
        - env
        - timeout
        - status
        - exit_code
        - reason
        - created_at
        - finished_at
      type: object
    TelnyxError:
      description: One error in the standard Telnyx error body.
      properties:
        code:
          description: >-
            Telnyx error code: a 5-digit string for general errors, e.g.
            `10009`. Sandboxes-specific errors are identified by their name in
            `title`.
          type: string
        detail:
          description: Human-readable explanation.
          type:
            - string
            - 'null'
        meta:
          description: Extra information.
          anyOf:
            - $ref: '#/components/schemas/TelnyxErrorMeta'
            - type: 'null'
        source:
          description: Where the error is.
          anyOf:
            - $ref: '#/components/schemas/TelnyxErrorSource'
            - type: 'null'
        title:
          description: >-
            Short, constant summary of the error. For Sandboxes-specific errors,
            the error's name, e.g. `quota_exceeded`.
          type: string
      required:
        - title
      type: object
    ExecReason:
      description: >-
        Why an exec is `failed` or `terminated`:

        - `sandbox_terminated`: the sandbox ended (or was ending) first;

        - `timeout`: the exec's `timeout` was reached;

        - `agent_unavailable`: the sandbox didn't confirm the start in time;

        - `cancelled`: killed with `SIGKILL` before its start was confirmed. If
        the start had in fact reached the sandbox, the exec moves on to what
        really ran, then exits from the kill;

        - `agent_error`: the sandbox returned an inconsistent answer.
      enum:
        - sandbox_terminated
        - timeout
        - agent_unavailable
        - cancelled
        - agent_error
      type: string
    ExecStatus:
      description: >-
        `starting` → `running` → `exited`. `failed`: the process was never
        confirmed started (see `reason`: `sandbox_terminated`,
        `agent_unavailable`, `cancelled` or `agent_error`). An
        `agent_unavailable` or `cancelled` exec can still move on to `running`,
        `exited` or `terminated` if its start did reach the sandbox.
        `terminated`: the process was stopped because the sandbox ended or the
        exec's `timeout` was reached.
      enum:
        - starting
        - running
        - exited
        - failed
        - terminated
      type: string
    TelnyxErrorMeta:
      description: Extra error information.
      properties:
        url:
          default: null
          description: Documentation page for the error code.
          type:
            - string
            - 'null'
      type: object
    TelnyxErrorSource:
      description: Where in the request the error was found.
      properties:
        parameter:
          default: null
          description: Name of the offending parameter.
          type:
            - string
            - 'null'
        pointer:
          default: null
          description: JSON pointer into the request body, e.g. `/timeout`.
          type:
            - string
            - 'null'
      type: object
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````