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

# Execute a command

> Execute a command and return process information.

Streaming: with `Accept: application/x-ndjson` (or `Accept: text/event-stream`, kept for compatibility) the response is NDJSON (`Content-Type: application/x-ndjson`), not SSE: one JSON object per line, `{"type": "...", "data": "..."}`.
`type` is `stdout` or `stderr` (`data` is a raw output chunk, sent as soon as the process writes it, newlines included; if the process finished before any chunk was streamed, its output is sent instead as one event per line, without the newline), `keepalive` (every 5 seconds, no data), `error` (`data` is the message, ends the stream) or `result` (last event, `data` is the ProcessResponse as a JSON string).



## OpenAPI

````yaml /reference/sandbox-api/openapi.json post /process
openapi: 3.0.0
info:
  description: API for manipulating filesystem, processes and network.
  title: Sandbox API
  contact: {}
  version: 0.0.1
servers:
  - url: https://{sandbox_host}
    description: >-
      Host from the sandbox's returned url, without the scheme or trailing
      slash.
    variables:
      sandbox_host:
        default: sandbox.example.com
security:
  - BearerAuth: []
paths:
  /process:
    post:
      tags:
        - process
      summary: Execute a command
      description: >-
        Execute a command and return process information.


        Streaming: with `Accept: application/x-ndjson` (or `Accept:
        text/event-stream`, kept for compatibility) the response is NDJSON
        (`Content-Type: application/x-ndjson`), not SSE: one JSON object per
        line, `{"type": "...", "data": "..."}`.

        `type` is `stdout` or `stderr` (`data` is a raw output chunk, sent as
        soon as the process writes it, newlines included; if the process
        finished before any chunk was streamed, its output is sent instead as
        one event per line, without the newline), `keepalive` (every 5 seconds,
        no data), `error` (`data` is the message, ends the stream) or `result`
        (last event, `data` is the ProcessResponse as a JSON string).
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ProcessRequest'
        description: Process execution request
        required: true
      responses:
        '200':
          description: Process information
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProcessResponse'
            application/x-ndjson:
              schema:
                type: string
                description: >-
                  NDJSON stream with one JSON event object per line. Each event
                  has a `type` and optional `data` string; the final `result`
                  event's `data` contains a serialized ProcessResponse.
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
            application/x-ndjson:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Unprocessable entity
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
            application/x-ndjson:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
            application/x-ndjson:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    ProcessRequest:
      type: object
      required:
        - command
      properties:
        command:
          type: string
          example: ls -la
        env:
          type: object
          additionalProperties:
            type: string
          example:
            PORT: '3000'
        keepAlive:
          description: >-
            Disable scale-to-zero while process runs. Default timeout is 600s
            (10 minutes). Set timeout to 0 for infinite.
          type: boolean
          example: false
        maxRestarts:
          description: >-
            Maximum number of restarts on failure. Set to a negative value (e.g.
            -1) for unlimited restarts.
          type: integer
          example: 3
        name:
          type: string
          example: my-process
        restartOnFailure:
          type: boolean
          example: true
        stdin:
          description: >-
            Open a writable stdin pipe, fed via POST /process/{identifier}/stdin
            and closed via DELETE. The pipe does not survive a sandbox-api
            restart: the process then sees EOF.
          type: boolean
          example: false
        timeout:
          description: >-
            Timeout in seconds. When keepAlive is true, defaults to 600s (10
            minutes). Set to 0 for infinite (no auto-kill).
          type: integer
          example: 30
        waitForCompletion:
          type: boolean
          example: false
        waitForPorts:
          type: array
          items:
            type: integer
          example:
            - 3000
            - 8080
        workingDir:
          type: string
          example: /home/user
    ProcessResponse:
      type: object
      required:
        - command
        - completedAt
        - exitCode
        - logs
        - name
        - pid
        - startedAt
        - status
        - stderr
        - stdout
        - workingDir
      properties:
        command:
          type: string
          example: ls -la
        completedAt:
          description: >-
            Completion time, same format as startedAt. Empty string while the
            process runs
          type: string
          example: Wed, 01 Jan 2023 12:01:00 GMT
        exitCode:
          type: integer
          example: 0
        keepAlive:
          description: Whether scale-to-zero is disabled for this process
          type: boolean
          example: false
        logs:
          type: string
          example: logs output
        maxRestarts:
          type: integer
          example: 3
        name:
          type: string
          example: my-process
        pid:
          type: string
          example: '1234'
        restartCount:
          type: integer
          example: 2
        restartOnFailure:
          type: boolean
          example: true
        startedAt:
          description: >-
            Start time as an HTTP date (RFC 1123, e.g. Wed, 01 Jan 2023 12:00:00
            GMT)
          type: string
          example: Wed, 01 Jan 2023 12:00:00 GMT
        status:
          type: string
          enum:
            - failed
            - killed
            - stopped
            - running
            - completed
          example: running
        stderr:
          type: string
          example: stderr output
        stdin:
          description: Whether the process was started with a writable stdin pipe
          type: boolean
          example: false
        stdout:
          type: string
          example: stdout output
        workingDir:
          type: string
          example: /home/user
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          example: Error message
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: Sandbox access token created through POST /v1/token.

````