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

# Run a sandbox command

> <Info>This API is in beta. Endpoints, fields, and behavior may still change, so avoid depending on it in production.</Info>

Runs a shell command inside the app's sandbox with bash and returns its output.

Every sandbox-bridge endpoint runs against the app's live sandbox, the same filesystem the AI edits, so a change here is visible in the app editor immediately.

A command that exits non-zero still answers 200. Read `exit_code` to tell a failed command from a failed request, and expect `stderr` to carry output on success too, since many tools log there.

Each call starts in the app root unless you set `cwd`, and `cd` does not carry over between calls, so chain directory changes inside one command instead. The default timeout is 120000 ms and the maximum is 600000 ms; a command that outruns its timeout answers 504 with the code `TIMEOUT`, and may keep running in the sandbox after the request ends. Output is capped at 1 MB per stream, and `truncated` tells you when that happened.

If a background save holds the sandbox for more than about 30 seconds, the call answers 409 with `SANDBOX_BUSY`; retry in a minute.

A command that would change git history or state (commit, reset, checkout of a branch, stash, push and the like) may be refused with 422 and `GIT_HISTORY_WRITE`, since Base44 commits your changes itself. Read-only git and `git restore <file>` still run.

This endpoint is limited to 30 requests per minute per app, its own budget rather than one shared with the other sandbox-bridge endpoints.

<Warning>A write is committed, not checkpointed. Only checkpoints appear in the app editor's version history, and a Restore or Revert there rolls the app back to the last checkpoint and discards everything written after it. Call [Create a sandbox checkpoint](/api-reference/create-a-sandbox-checkpoint) when you finish a unit of work and before you stop.</Warning>

<Note>The bridge needs a Builder plan or higher on the app's workspace, and answers 402 below that (`PREMIUM_REQUIRED`). Where sandbox calls are metered, each call is charged to the app's integration credits and a workspace that has none left answers 402 with `CREDITS_EXHAUSTED`. The bridge is unavailable for agent apps. A personal API key works as-is, and so does a workspace API key, which acts as the workspace owner. An OAuth access token needs the `sandbox:write` scope.</Note>

<Tip>Every error response carries a stable `extra_data.code` alongside the human-readable `message`. Branch on the code rather than on the message text or the status.</Tip>



## OpenAPI

````yaml /developers/references/app-management/app-management-openapi.json post /api/apps/{app_id}/sandbox-bridge/run_command
openapi: 3.1.0
info:
  title: Base44 App Management API
  version: 1.0.0
servers:
  - url: https://app.base44.com
security:
  - PersonalAccessTokenAuth: []
paths:
  /api/apps/{app_id}/sandbox-bridge/run_command:
    post:
      summary: Run a sandbox command
      description: >-
        <Info>This API is in beta. Endpoints, fields, and behavior may still
        change, so avoid depending on it in production.</Info>


        Runs a shell command inside the app's sandbox with bash and returns its
        output.


        Every sandbox-bridge endpoint runs against the app's live sandbox, the
        same filesystem the AI edits, so a change here is visible in the app
        editor immediately.


        A command that exits non-zero still answers 200. Read `exit_code` to
        tell a failed command from a failed request, and expect `stderr` to
        carry output on success too, since many tools log there.


        Each call starts in the app root unless you set `cwd`, and `cd` does not
        carry over between calls, so chain directory changes inside one command
        instead. The default timeout is 120000 ms and the maximum is 600000 ms;
        a command that outruns its timeout answers 504 with the code `TIMEOUT`,
        and may keep running in the sandbox after the request ends. Output is
        capped at 1 MB per stream, and `truncated` tells you when that happened.


        If a background save holds the sandbox for more than about 30 seconds,
        the call answers 409 with `SANDBOX_BUSY`; retry in a minute.


        A command that would change git history or state (commit, reset,
        checkout of a branch, stash, push and the like) may be refused with 422
        and `GIT_HISTORY_WRITE`, since Base44 commits your changes itself.
        Read-only git and `git restore <file>` still run.


        This endpoint is limited to 30 requests per minute per app, its own
        budget rather than one shared with the other sandbox-bridge endpoints.


        <Warning>A write is committed, not checkpointed. Only checkpoints appear
        in the app editor's version history, and a Restore or Revert there rolls
        the app back to the last checkpoint and discards everything written
        after it. Call [Create a sandbox
        checkpoint](/api-reference/create-a-sandbox-checkpoint) when you finish
        a unit of work and before you stop.</Warning>


        <Note>The bridge needs a Builder plan or higher on the app's workspace,
        and answers 402 below that (`PREMIUM_REQUIRED`). Where sandbox calls are
        metered, each call is charged to the app's integration credits and a
        workspace that has none left answers 402 with `CREDITS_EXHAUSTED`. The
        bridge is unavailable for agent apps. A personal API key works as-is,
        and so does a workspace API key, which acts as the workspace owner. An
        OAuth access token needs the `sandbox:write` scope.</Note>


        <Tip>Every error response carries a stable `extra_data.code` alongside
        the human-readable `message`. Branch on the code rather than on the
        message text or the status.</Tip>
      operationId: run_command_endpoint_api_apps__app_id__sandbox_bridge_run_command_post
      parameters:
        - name: app_id
          in: path
          required: true
          schema:
            type: string
            description: ID of the app whose sandbox to operate on.
            title: App Id
          description: ID of the app whose sandbox to operate on.
          example: 6820f3a4e7b91d003c45a1f2
      requestBody:
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              default: {}
              title: RunSandboxCommand
              properties:
                branch_id:
                  anyOf:
                    - type: string
                    - type: 'null'
                  description: Optional Base44 branch ID. Omit to operate on main.
                  title: Branch Id
                command:
                  description: Shell command to execute via bash inside the sandbox.
                  maxLength: 100000
                  minLength: 1
                  title: Command
                  type: string
                cwd:
                  anyOf:
                    - type: string
                    - type: 'null'
                  description: >-
                    Working dir relative to the app root. `cd` does not persist
                    across calls — use this or chain commands.
                  title: Cwd
                timeout_ms:
                  default: 120000
                  description: Timeout in milliseconds (default 120000, max 600000).
                  maximum: 600000
                  minimum: 1
                  title: Timeout Ms
                  type: integer
              required:
                - command
            example:
              command: npm install
              timeout_ms: 300000
        required: true
      responses:
        '200':
          description: The command ran. Read `exit_code` for its result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RunCommandResult'
        '401':
          description: Missing or invalid credentials.
        '402':
          description: The app's workspace plan doesn't include the sandbox bridge.
        '403':
          description: >-
            You don't have access to this app, the app is blocked, or your OAuth
            token is missing the scope this endpoint needs.
        '404':
          description: App not found.
        '409':
          description: >-
            The app is on a branch that can't be written to, or the sandbox is
            busy saving background changes (`SANDBOX_BUSY`; retry shortly).
        '422':
          description: >-
            The request body is invalid, or the command would change git history
            or state (`GIT_HISTORY_WRITE`).
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/HTTPValidationError'
                  - title: SandboxBridgeError
                    type: object
                    required:
                      - extra_data
                    properties:
                      message:
                        type: string
                        example: >-
                          run_command cannot change git history (commit, reset,
                          ...).
                      extra_data:
                        type: object
                        properties:
                          code:
                            type: string
                            example: GIT_HISTORY_WRITE
                      request_id:
                        type: string
        '429':
          description: Rate limit exceeded (30 requests per minute).
        '503':
          description: >-
            Database temporarily unavailable (`database_unavailable`): the data
            cluster did not answer in time. Retry after the `Retry-After`
            seconds.
          headers:
            Retry-After:
              description: Seconds to wait before retrying.
              schema:
                type: integer
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
              examples:
                database_unavailable:
                  summary: database_unavailable
                  value:
                    error:
                      code: database_unavailable
                      message: Database temporarily unavailable, please retry
                      details: {}
        '504':
          description: >-
            The command outran `timeout_ms` (`TIMEOUT`). The command may still
            be running in the sandbox.
      security:
        - PersonalAccessTokenAuth:
            - full_access
        - WorkspaceApiKeyAuth:
            - full_access
        - WorkspaceApiKeyBearerAuth:
            - full_access
components:
  schemas:
    RunCommandResult:
      properties:
        stdout:
          type: string
          title: Stdout
          description: Everything the command wrote to standard output.
          example: |
            added 12 packages in 3s
        stderr:
          type: string
          title: Stderr
          description: >-
            Everything the command wrote to standard error. Populated on success
            too, since many tools log there.
          example: ''
        exit_code:
          type: integer
          title: Exit Code
          description: >-
            The command's exit status. `0` means success. A non-zero status is
            still a 200 from this endpoint: the command ran and failed, which is
            not a request error.
          example: 0
        truncated:
          type: boolean
          title: Truncated
          description: >-
            `true` when the output hit the 1 MB cap and was cut short. `stdout`
            and `stderr` are each capped, and either one hitting it sets this.
          example: false
        duration_ms:
          type: integer
          title: Duration Ms
          description: How long the command took, in milliseconds.
          example: 3120
        unsaved_large_files:
          items:
            $ref: '#/components/schemas/UnsavedLargeFile'
          type: array
          title: Unsaved Large Files
          description: >-
            Files in the app over the 32 MiB per-file limit. They can't be saved
            to the app's code, so they stay in the sandbox only: the published
            app doesn't have them, and they're lost if the sandbox is rebuilt.
            Checked after commands that can change files; empty after read-only
            ones.
          example: []
      type: object
      required:
        - stdout
        - stderr
        - exit_code
        - truncated
        - duration_ms
        - unsaved_large_files
      title: RunCommandResult
      description: What a command left behind.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    StandardErrorEnvelope:
      properties:
        error:
          $ref: '#/components/schemas/StandardError'
          description: What went wrong.
      type: object
      required:
        - error
      title: StandardErrorEnvelope
      description: The error body returned in the standard envelope.
    UnsavedLargeFile:
      properties:
        path:
          type: string
          title: Path
          description: Path of the file, relative to the app root.
          example: backup/site.tar.gz
        size_bytes:
          type: integer
          title: Size Bytes
          description: Size of the file in bytes.
          example: 139460608
      type: object
      required:
        - path
        - size_bytes
      title: UnsavedLargeFile
      description: A file in the app that is too large to be saved to its code.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    StandardError:
      properties:
        code:
          type: string
          title: Code
          description: >-
            Stable machine-readable cause of the failure. Match on this, not on
            `message`.
          example: not_found
        message:
          type: string
          title: Message
          description: Human-readable explanation. It isn't a stable contract.
          example: App not found
        details:
          additionalProperties: true
          type: object
          title: Details
          description: >-
            Structured context for the failure, or an empty object when there's
            none.
          example: {}
      type: object
      required:
        - code
        - message
      title: StandardError
  securitySchemes:
    PersonalAccessTokenAuth:
      type: http
      scheme: bearer
      description: >-
        Personal access token, sent as `Authorization: Bearer <token>`. Each
        operation lists the permission it needs: `read_only` or `full_access`. A
        full-access token can call every operation. A read-only token can call
        only the operations that list `read_only`; anything else returns 403
        `read_only_credential_route_not_allowed`.
    WorkspaceApiKeyAuth:
      type: apiKey
      in: header
      name: api_key
      description: >-
        Workspace API key, sent as `api_key: <key>`. Each operation that accepts
        one lists what the key needs: a permission, `read_only` or
        `full_access`, like a personal access token, or a scope. A key without
        the scope gets 403 `workspace_api_key_scope_required`.
    WorkspaceApiKeyBearerAuth:
      type: http
      scheme: bearer
      description: >-
        Workspace API key, sent as `Authorization: Bearer <key>`. Accepted
        wherever `api_key` is, with the same permission.

````

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