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

# Execute Command

> Execute a command in the sprite environment via WebSocket. Commands continue running after disconnect; use `max_run_after_disconnect` to control timeout. Supports TTY and non-TTY modes.



## AsyncAPI

````yaml sprites/api/asyncapi.json exec
id: exec
title: Execute Command
description: >-
  Execute a command in the sprite environment via WebSocket. Commands continue
  running after disconnect; use `max_run_after_disconnect` to control timeout.
  Supports TTY and non-TTY modes.
servers:
  - id: production
    protocol: wss
    host: api.sprites.dev
    bindings: []
    variables: []
address: /v1/sprites/{name}/exec
parameters:
  - id: name
    jsonSchema:
      type: string
      description: Sprite name within the organization.
    description: Sprite name within the organization.
    type: string
    required: true
    deprecated: false
bindings: []
operations:
  - &ref_1
    id: execReceive
    title: 'Execute Command: messages from client'
    description: Messages the Sprites API receives from the client.
    type: receive
    messages:
      - &ref_3
        id: ResizeMessage
        contentType: application/json
        payload:
          - name: ResizeMessage
            type: object
            properties:
              - name: type
                type: string
                description: resize
                required: true
              - name: cols
                type: integer
                description: New column count
                required: true
              - name: rows
                type: integer
                description: New row count
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            type:
              type: string
              const: resize
              x-parser-schema-id: <anonymous-schema-2>
            cols:
              type: integer
              minimum: 0
              maximum: 65535
              description: New column count
              x-parser-schema-id: <anonymous-schema-3>
            rows:
              type: integer
              minimum: 0
              maximum: 65535
              description: New row count
              x-parser-schema-id: <anonymous-schema-4>
          required:
            - type
            - cols
            - rows
          examples:
            - cols: 180
              rows: 50
              type: resize
          x-parser-schema-id: ResizeMessage
        title: Resize message
        example: |-
          {
            "cols": 180,
            "rows": 50,
            "type": "resize"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: ResizeMessage
      - &ref_4
        id: execStdinData
        contentType: application/octet-stream
        payload:
          - type: string
            format: binary
            description: 'stdin data. Frame prefix: `0x00`.'
            x-parser-schema-id: <anonymous-schema-19>
            name: stdin data (0x00)
        headers: []
        jsonPayloadSchema:
          type: string
          format: binary
          description: 'stdin data. Frame prefix: `0x00`.'
          x-parser-schema-id: <anonymous-schema-19>
        title: stdin data (0x00)
        description: 'stdin data. Frame prefix: `0x00`.'
        example: '"0x00 0x6c 0x73 0x0a (sends ''ls\\n'')"'
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: execStdinData
      - &ref_5
        id: execStdinEofSignal
        contentType: application/octet-stream
        payload:
          - type: string
            format: binary
            description: 'stdin EOF signal. Frame prefix: `0x04`.'
            x-parser-schema-id: <anonymous-schema-23>
            name: stdin EOF signal (0x04)
        headers: []
        jsonPayloadSchema:
          type: string
          format: binary
          description: 'stdin EOF signal. Frame prefix: `0x04`.'
          x-parser-schema-id: <anonymous-schema-23>
        title: stdin EOF signal (0x04)
        description: 'stdin EOF signal. Frame prefix: `0x04`.'
        example: '"0x04 (signals end of input)"'
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: execStdinEofSignal
    bindings: []
    extensions: &ref_0
      - id: x-parser-unique-object-id
        value: exec
  - &ref_2
    id: execSend
    title: 'Execute Command: messages to client'
    description: Messages the Sprites API sends to the client.
    type: send
    messages:
      - &ref_6
        id: SessionInfoMessage
        contentType: application/json
        payload:
          - name: SessionInfoMessage
            type: object
            properties:
              - name: type
                type: string
                description: session_info
                required: true
              - name: session_id
                type: string
                description: Session ID
                required: true
              - name: command
                type: string
                description: Command being executed
                required: true
              - name: created
                type: integer
                description: Unix timestamp of session creation
                required: true
              - name: cols
                type: integer
                description: Terminal columns (TTY mode only)
                required: true
              - name: rows
                type: integer
                description: Terminal rows (TTY mode only)
                required: true
              - name: is_owner
                type: boolean
                description: Whether this attachment owns the session
                required: true
              - name: tty
                type: boolean
                description: Whether session is in TTY mode
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            type:
              type: string
              const: session_info
              x-parser-schema-id: <anonymous-schema-5>
            session_id:
              type: string
              description: Session ID
              x-parser-schema-id: <anonymous-schema-6>
            command:
              type: string
              description: Command being executed
              x-parser-schema-id: <anonymous-schema-7>
            created:
              type: integer
              format: int64
              description: Unix timestamp of session creation
              x-parser-schema-id: <anonymous-schema-8>
            cols:
              type: integer
              minimum: 0
              maximum: 65535
              description: Terminal columns (TTY mode only)
              x-parser-schema-id: <anonymous-schema-9>
            rows:
              type: integer
              minimum: 0
              maximum: 65535
              description: Terminal rows (TTY mode only)
              x-parser-schema-id: <anonymous-schema-10>
            is_owner:
              type: boolean
              description: Whether this attachment owns the session
              x-parser-schema-id: <anonymous-schema-11>
            tty:
              type: boolean
              description: Whether session is in TTY mode
              x-parser-schema-id: <anonymous-schema-12>
          required:
            - type
            - session_id
            - command
            - created
            - cols
            - rows
            - is_owner
            - tty
          examples:
            - cols: 120
              command: bash
              created: 1767609000
              is_owner: true
              rows: 40
              session_id: '1847'
              tty: true
              type: session_info
          x-parser-schema-id: SessionInfoMessage
        title: Session info message
        example: |-
          {
            "cols": 120,
            "command": "bash",
            "created": 1767609000,
            "is_owner": true,
            "rows": 40,
            "session_id": "1847",
            "tty": true,
            "type": "session_info"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: SessionInfoMessage
      - &ref_7
        id: ExitMessage
        contentType: application/json
        payload:
          - name: ExitMessage
            type: object
            properties:
              - name: type
                type: string
                description: exit
                required: true
              - name: exit_code
                type: integer
                description: Process exit code
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            type:
              type: string
              const: exit
              x-parser-schema-id: <anonymous-schema-13>
            exit_code:
              type: integer
              description: Process exit code
              x-parser-schema-id: <anonymous-schema-14>
          required:
            - type
            - exit_code
          examples:
            - exit_code: 0
              type: exit
          x-parser-schema-id: ExitMessage
        title: Exit message
        example: |-
          {
            "exit_code": 0,
            "type": "exit"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: ExitMessage
      - &ref_8
        id: PortNotificationMessage
        contentType: application/json
        payload:
          - name: PortNotificationMessage
            type: object
            properties:
              - name: type
                type: string
                description: Notification type
                enumValues:
                  - port_opened
                  - port_closed
                required: true
              - name: port
                type: integer
                description: Port number
                required: true
              - name: address
                type: string
                description: Proxy URL for accessing the port
                required: true
              - name: pid
                type: integer
                description: Process ID that opened/closed the port
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            type:
              type: string
              enum:
                - port_opened
                - port_closed
              description: Notification type
              x-parser-schema-id: <anonymous-schema-15>
            port:
              type: integer
              description: Port number
              x-parser-schema-id: <anonymous-schema-16>
            address:
              type: string
              description: Proxy URL for accessing the port
              x-parser-schema-id: <anonymous-schema-17>
            pid:
              type: integer
              description: Process ID that opened/closed the port
              x-parser-schema-id: <anonymous-schema-18>
          required:
            - type
            - port
            - address
            - pid
          examples:
            - address: https://my-sprite.sprites.dev:3000
              pid: 1847
              port: 3000
              type: port_opened
          x-parser-schema-id: PortNotificationMessage
        title: Port notification message
        example: |-
          {
            "address": "https://my-sprite.sprites.dev:3000",
            "pid": 1847,
            "port": 3000,
            "type": "port_opened"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: PortNotificationMessage
      - &ref_9
        id: execStdoutData
        contentType: application/octet-stream
        payload:
          - type: string
            format: binary
            description: 'stdout data. Frame prefix: `0x01`.'
            x-parser-schema-id: <anonymous-schema-20>
            name: stdout data (0x01)
        headers: []
        jsonPayloadSchema:
          type: string
          format: binary
          description: 'stdout data. Frame prefix: `0x01`.'
          x-parser-schema-id: <anonymous-schema-20>
        title: stdout data (0x01)
        description: 'stdout data. Frame prefix: `0x01`.'
        example: '"0x01 0x66 0x6f 0x6f 0x0a (receives ''foo\\n'')"'
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: execStdoutData
      - &ref_10
        id: execStderrData
        contentType: application/octet-stream
        payload:
          - type: string
            format: binary
            description: 'stderr data. Frame prefix: `0x02`.'
            x-parser-schema-id: <anonymous-schema-21>
            name: stderr data (0x02)
        headers: []
        jsonPayloadSchema:
          type: string
          format: binary
          description: 'stderr data. Frame prefix: `0x02`.'
          x-parser-schema-id: <anonymous-schema-21>
        title: stderr data (0x02)
        description: 'stderr data. Frame prefix: `0x02`.'
        example: '"0x02 0x65 0x72 0x72 0x6f 0x72 0x0a (receives ''error\\n'')"'
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: execStderrData
      - &ref_11
        id: execExitCode
        contentType: application/octet-stream
        payload:
          - type: string
            format: binary
            description: 'exit code (single byte). Frame prefix: `0x03`.'
            x-parser-schema-id: <anonymous-schema-22>
            name: exit code (single byte) (0x03)
        headers: []
        jsonPayloadSchema:
          type: string
          format: binary
          description: 'exit code (single byte). Frame prefix: `0x03`.'
          x-parser-schema-id: <anonymous-schema-22>
        title: exit code (single byte) (0x03)
        description: 'exit code (single byte). Frame prefix: `0x03`.'
        example: '"0x03 0x00 (exit code 0)"'
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: execExitCode
    bindings: []
    extensions: *ref_0
sendOperations:
  - *ref_1
receiveOperations:
  - *ref_2
sendMessages:
  - *ref_3
  - *ref_4
  - *ref_5
receiveMessages:
  - *ref_6
  - *ref_7
  - *ref_8
  - *ref_9
  - *ref_10
  - *ref_11
extensions:
  - id: x-parser-unique-object-id
    value: exec
securitySchemes:
  - id: bearerAuth
    name: bearerAuth
    type: http
    description: >-
      Sprites API token in the form `<org>/<id>/<secret>`, sent as
      `Authorization: Bearer <token>` on the upgrade request.
    scheme: bearer
    extensions: []

````