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

# Run a Command

> Runs a shell command in a running sandbox and returns what it printed. Linux runs it with `sh -c`, Windows with PowerShell.

The call waits up to 60 seconds. A command still running then goes on inside the sandbox, and the answer comes back with `finished: false` and `exit_code: null`. Start longer jobs in the background (for example with `nohup ... &`) and check on them with later commands.

stdout and stderr are each cut at 64 KB, and `truncated` says when. The sandbox's environment variables are loaded first. A command counts as activity, so it resets the auto-stop timer. Every command is in the sandbox's logs.

Rate limit: 120 a minute, counted apart from the rest of the API, see [Limits](/sandboxes#limits).



## OpenAPI

````yaml POST /sandboxes/{sandbox}/exec
openapi: 3.0.3
info:
  title: CloudBlast API
  description: >-
    The CloudBlast V2 API provides a modern RESTful interface for managing your
    cloud infrastructure programmatically. All responses follow a consistent `{
    "data": ... }` or `{ "error": ... }` format.
  version: 2.0.0
servers:
  - url: https://console.cloudblast.io/api/v2
    description: Production
security:
  - bearerAuth: []
paths:
  /sandboxes/{sandbox}/exec:
    post:
      tags:
        - Sandboxes
      summary: Run a command
      description: >-
        Runs a shell command in a running sandbox and returns what it printed.
        Linux runs it with `sh -c`, Windows with PowerShell.


        The call waits up to 60 seconds. A command still running then goes on
        inside the sandbox, and the answer comes back with `finished: false` and
        `exit_code: null`. Start longer jobs in the background (for example with
        `nohup ... &`) and check on them with later commands.


        stdout and stderr are each cut at 64 KB, and `truncated` says when. The
        sandbox's environment variables are loaded first. A command counts as
        activity, so it resets the auto-stop timer. Every command is in the
        sandbox's logs.


        Rate limit: 120 a minute, counted apart from the rest of the API, see
        [Limits](/sandboxes#limits).
      operationId: runSandboxCommand
      parameters:
        - $ref: '#/components/parameters/SandboxIdentifier'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SandboxExecRequest'
      responses:
        '200':
          description: What the command printed
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/SandboxExecResult'
        '401':
          $ref: '#/components/responses/Unauthenticated'
        '404':
          $ref: '#/components/responses/SandboxNotFound'
        '409':
          $ref: '#/components/responses/SandboxNotRunning'
        '422':
          $ref: '#/components/responses/SandboxValidationError'
        '503':
          $ref: '#/components/responses/SandboxNoAnswer'
components:
  parameters:
    SandboxIdentifier:
      name: sandbox
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: >-
        Sandbox UUID, as returned in the `uuid` field. Only the full UUID works
        here.
      example: 9b2f4c1e-7d3a-4e8b-a5c6-1f0e2d3c4b5a
  schemas:
    SandboxExecRequest:
      type: object
      required:
        - command
      properties:
        command:
          type: string
          maxLength: 8000
          description: >-
            The shell command. Run with `sh -c` on Linux and with PowerShell on
            Windows.
          example: python3 --version && echo $MODE
    SandboxExecResult:
      type: object
      properties:
        finished:
          type: boolean
          description: >-
            False when the command was still running after 60 seconds. It goes
            on inside the sandbox, but its output is not waited for.
          example: true
        exit_code:
          type: integer
          nullable: true
          description: The command's exit code. `null` when it has not finished.
          example: 0
        stdout:
          type: string
          description: What the command printed, up to 64 KB.
          example: |
            Python 3.12.3
            test
        stderr:
          type: string
          description: What the command printed as errors, up to 64 KB.
          example: ''
        truncated:
          type: boolean
          description: True when stdout or stderr was cut at 64 KB.
          example: false
        seconds:
          type: number
          description: How long the call took, in seconds.
          example: 0.41
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              description: Machine-readable error code
            message:
              type: string
              description: Human-readable error message
          required:
            - code
            - message
    SandboxError:
      type: object
      description: >-
        How the sandbox endpoints answer an error: a `message`, not an error
        code. `errors` is only there when a request field failed validation.
      properties:
        message:
          type: string
          description: What went wrong, in plain words.
          example: Start the sandbox first.
        errors:
          type: object
          description: Messages per field, only when a field failed validation.
          additionalProperties:
            type: array
            items:
              type: string
          example:
            image_id:
              - The image id field is required.
      required:
        - message
  responses:
    Unauthenticated:
      description: Authentication failed
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: UNAUTHENTICATED
              message: >-
                Missing or invalid Authorization header. Use: Authorization:
                Bearer <token>
    SandboxNotFound:
      description: No sandbox with this UUID on your account
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxError'
          example:
            message: Sandbox not found.
    SandboxNotRunning:
      description: The sandbox is not running. Start it first.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxError'
          example:
            message: Start the sandbox first.
    SandboxValidationError:
      description: >-
        A field failed validation. Send `Accept: application/json` to get this
        as JSON: without it, the answer is a 302 redirect.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxError'
          example:
            message: The command field is required.
            errors:
              command:
                - The command field is required.
    SandboxNoAnswer:
      description: >-
        The sandbox did not answer. If it was just started, try again in a few
        seconds.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxError'
          example:
            message: >-
              The sandbox did not answer. If it was just started, try again in a
              few seconds.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        API token from your CloudBlast account settings. Pass as `Authorization:
        Bearer <token>`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.