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

# Execute a command in a sandbox

> Starts an asynchronous shell execution in the sandbox. The request body keeps the
`action=exec` and `parameters` shape used by the runtime contract. The effective URL is
the sandbox data-plane host; the sandbox ID is obtained from the leftmost Host label and
is not repeated in the path. The endpoint does not include the control-plane `/api/v2` prefix.
When `wait=true`, the server waits for a terminal result for at most
`wait_timeout_seconds` seconds; a timeout returns `202` without cancelling the execution.
Cancelling an execution, or reaching its timeout, stops the command and every process it started: all processes in the command's process group receive SIGTERM and then SIGKILL, so a pipeline or `bash -c "a; b"` leaves nothing behind. A process that deliberately leaves the group (for example with `setsid`) is not stopped. A command that exits on its own does not stop the background processes it started, so a server started with `nohup app > app.log 2>&1 &` keeps running; redirect the output of such a process, because the execution only ends once the command's stdout and stderr are closed. Pausing the sandbox does not end the execution; the time spent paused still counts toward the execution's timeout.
The request body is limited to 1 MiB. Unknown query parameters are rejected with 400. A sandbox allows at most 10 non-terminal executions at the same time; further requests return 429 `Execution.ConcurrencyLimitExceeded` until one completes.




## OpenAPI

````yaml /api-spec/sandbox_api.yaml post /executions
openapi: 3.0.3
info:
  title: GMI Sandbox API
  description: >-
    REST API for GMI Sandbox: create isolated execution environments from
    templates or durable snapshots, manage their lifecycle on the control plane,
    and run commands or transfer files through each sandbox's own data plane.
  contact:
    name: GMI Cloud Support
    email: support@gmicloud.ai
  version: '2.0'
servers:
  - url: https://console.gmicloud.ai/api/v2
    description: Control plane
security:
  - bearerAuth: []
tags:
  - name: Sandbox
    description: |
      Sandbox instance lifecycle management (Sandbox v2, /api/v2/sandboxes)
  - name: SandboxSnapshot
    description: Durable sandbox snapshot management (Sandbox v2, `/api/v2/snapshots`)
  - name: SandboxTemplate
    description: Sandbox template management (Sandbox v2, `/api/v2/templates`)
  - name: Sandbox-Exec
    description: >
      Sandbox execution data plane (accessed via the sandbox host and sandbox
      access token). These endpoints are not under the control plane's `/api/v2`
      path; clients connect directly to `https://{sandbox_key}.{domain}` and
      authenticate with `X-Access-Token`.
  - name: Sandbox-Shell
    description: >
      Sandbox interactive terminal (PTY) data plane. **These endpoints are not
      under `/api/v2`**: clients connect directly to
      `https://{sandbox_key}.{domain}` and authenticate with `X-Access-Token`.
      `{sandbox_key}`, `{domain}` and the `X-Access-Token` value are the
      `sandbox_key`, `domain` and `sandbox_access_token` returned by the
      control-plane create/connect endpoints; no extra endpoint is needed.


      Each sandbox has exactly **one logical shell session** and at most **one
      active WebSocket connection** at a time (a second concurrent attach is
      refused at handshake with `409`). Disconnecting does not destroy the shell
      — re-attaching resumes the same session; only `POST /shell/control` with
      `action=close` destroys it.
  - name: Sandbox-Files
    description: >
      Sandbox file data plane (`/files`). **These endpoints are not under
      `/api/v2`** and do not use `Authorization: Bearer`: they are served by the
      sandbox's own data-plane entry point — clients connect directly to
      `https://{sandbox_key}.{domain}` and authenticate with `X-Access-Token`.
      `{sandbox_key}` is the `sandbox_key` returned by the create/connect
      endpoints, used for data-plane host addressing. `{domain}` and
      `X-Access-Token` are the `domain` and `sandbox_access_token` from the same
      responses — no extra endpoint is needed to obtain them.


      This split is not historical baggage but the nature of a data plane: file
      transfer is long-lived, high-volume, and addressed per sandbox, differing
      from the control plane's short requests in both capacity model and failure
      domain, so they do not share an entry point.


      **One unified abstraction.** The same contract is served by two backend
      kinds (an in-sandbox file service / a data-center data-plane proxy);
      clients need not — and cannot — tell them apart. The cost is that the
      contract is their intersection: `Content-Length` on download and resumable
      download (`Range`/`206`) are **optional capabilities** that vary by data
      center, and clients must work correctly when they are absent. See the
      per-operation notes below.
paths:
  /executions:
    servers:
      - url: https://{sandbox_key}.{domain}
        description: >
          Sandbox data-plane entry point. Both variables come from the
          create/connect response: `sandbox_key` is `data.sandbox_key`, `domain`
          is `data.domain`.
        variables:
          sandbox_key:
            default: sandbox-key
            description: >-
              Sandbox key (the `sandbox_key` returned by the create/connect
              endpoints)
          domain:
            default: sandbox.example.com
            description: >
              The `domain` returned verbatim by the create/connect endpoints.
              Its default naming shape is `{idc-name}.{root-hostname}`, but
              clients must not assemble or derive it themselves.
    post:
      tags:
        - Sandbox-Exec
      summary: Execute a command in a sandbox
      description: >
        Starts an asynchronous shell execution in the sandbox. The request body
        keeps the

        `action=exec` and `parameters` shape used by the runtime contract. The
        effective URL is

        the sandbox data-plane host; the sandbox ID is obtained from the
        leftmost Host label and

        is not repeated in the path. The endpoint does not include the
        control-plane `/api/v2` prefix.

        When `wait=true`, the server waits for a terminal result for at most

        `wait_timeout_seconds` seconds; a timeout returns `202` without
        cancelling the execution.

        Cancelling an execution, or reaching its timeout, stops the command and
        every process it started: all processes in the command's process group
        receive SIGTERM and then SIGKILL, so a pipeline or `bash -c "a; b"`
        leaves nothing behind. A process that deliberately leaves the group (for
        example with `setsid`) is not stopped. A command that exits on its own
        does not stop the background processes it started, so a server started
        with `nohup app > app.log 2>&1 &` keeps running; redirect the output of
        such a process, because the execution only ends once the command's
        stdout and stderr are closed. Pausing the sandbox does not end the
        execution; the time spent paused still counts toward the execution's
        timeout.

        The request body is limited to 1 MiB. Unknown query parameters are
        rejected with 400. A sandbox allows at most 10 non-terminal executions
        at the same time; further requests return 429
        `Execution.ConcurrencyLimitExceeded` until one completes.
      operationId: createSandboxExecution
      parameters:
        - $ref: '#/components/parameters/SandboxExecRequestIDParam'
        - $ref: '#/components/parameters/SandboxExecWaitParam'
        - $ref: '#/components/parameters/SandboxExecWaitTimeoutParam'
        - $ref: '#/components/parameters/SandboxExecIdempotencyKeyParam'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SandboxExecRequest'
            example:
              action: exec
              parameters:
                command: printf '%s\n' "$APP_ENV"
                envs:
                  APP_ENV: production
                cwd: /workspace
      responses:
        '200':
          description: Execution completed within the requested wait window.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SandboxExecResultResponse'
        '202':
          description: Execution accepted, or still running when the wait window expired.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SandboxExecAcceptedResponse'
        '400':
          $ref: '#/components/responses/SandboxExecBadRequest'
        '401':
          $ref: '#/components/responses/SandboxExecUnauthorized'
        '409':
          $ref: '#/components/responses/SandboxExecRuntimeNotRunning'
        '429':
          $ref: '#/components/responses/SandboxExecRateLimited'
        '500':
          $ref: '#/components/responses/SandboxExecInternalError'
        '503':
          $ref: '#/components/responses/SandboxExecUnavailable'
      security:
        - sandboxAccessToken: []
      servers:
        - url: https://{sandbox_key}.{domain}
          description: Sandbox data-plane host
          variables:
            sandbox_key:
              default: sandbox-key
              description: >-
                Data-plane addressing key (`sandbox_key` from the control-plane
                response).
            domain:
              default: sandbox.example.com
              description: Sandbox data-plane domain from the control-plane response.
components:
  parameters:
    SandboxExecRequestIDParam:
      name: X-Request-ID
      in: header
      required: false
      description: >
        Ignored. The server generates its own request ID (`req-<uuid>`) for
        every request and

        returns it in the `X-Request-ID` response header and the body's
        `request_id`.
      schema:
        type: string
        minLength: 1
        maxLength: 128
    SandboxExecWaitParam:
      name: wait
      in: query
      required: false
      description: >-
        Wait for a terminal result before responding. Defaults to false. Must be
        `true` or `false`; any other value returns 400
        `Execution.InvalidRequest`.
      schema:
        type: boolean
        default: false
    SandboxExecWaitTimeoutParam:
      name: wait_timeout_seconds
      in: query
      required: false
      description: >
        Maximum time to wait when `wait=true`, in seconds. Values from 1 through
        25

        are accepted. A wait timeout never cancels the execution.

        Only valid together with `wait=true` (otherwise 400
        `Execution.InvalidRequest`); a value outside 1..25 or not an integer
        returns 400 `Execution.InvalidWaitTimeout`.
      schema:
        type: integer
        minimum: 1
        maximum: 25
        default: 25
    SandboxExecIdempotencyKeyParam:
      name: Idempotency-Key
      in: header
      required: false
      description: >-
        Optional key that makes `POST /executions` safe to retry: 1 to 64
        printable ASCII characters without whitespace. Resubmitting the same key
        with identical parameters returns the same execution in its current
        state instead of starting a new one; the same key with different
        parameters returns 400 `Execution.IdempotentParameterMismatch`. A key
        that is empty or not 1 to 64 printable ASCII characters returns 400
        `Execution.InvalidRequest`. The key is remembered for a limited time
        after the execution reaches a terminal state; after that, the same key
        starts a new execution.
      schema:
        type: string
        minLength: 1
        maxLength: 64
  schemas:
    SandboxExecRequest:
      type: object
      additionalProperties: false
      required:
        - action
        - parameters
      properties:
        action:
          type: string
          enum:
            - exec
          description: >-
            Execution action. The sealed data plane currently supports exec
            only.
        parameters:
          type: object
          additionalProperties: false
          required:
            - command
          properties:
            command:
              type: string
              minLength: 1
              description: >-
                Shell command to execute. Required and non-empty; at most 128
                KiB (counted in bytes) and must not contain NUL. A violation
                returns 400 `Execution.InvalidRequest`.
            envs:
              type: object
              additionalProperties:
                type: string
              description: >-
                Environment variables for the command. Names must be valid
                environment variable names (letters, digits and underscore, not
                starting with a digit) of at most 128 bytes, and each value is
                at most 64 KiB; otherwise the request returns 400
                `Execution.InvalidRequest`.
            cwd:
              type: string
              description: >-
                Working directory the command runs in (relative paths in the
                command resolve against it). It must be absolute and normalized:
                no `.`, `..` or empty segments (a trailing `/` is normalized
                away); otherwise 400 `Execution.InvalidRequest`. When omitted,
                defaults to the template's working directory (the image or
                Dockerfile WORKDIR; depends on the template and IDC, for example
                `/` or `/home/user`; pass `cwd` explicitly when it matters). If
                the directory does not exist the execution ends with status
                `failed` and `failure_reason` `cwd_not_found`. If the path
                exists but is not a directory the execution ends with `failed`
                and `failure_reason` `cwd_not_directory`.
            execution_timeout_seconds:
              type: integer
              format: int32
              minimum: 1
              maximum: 3600
              default: 300
              description: >-
                Time limit for this command, in seconds. When the limit is
                reached the command is terminated (SIGTERM, then SIGKILL after a
                grace period) and the execution ends with status `timed_out` and
                a null `exit_code`. A value outside 1..3600 returns 400. This is
                unrelated to `wait_timeout_seconds`, which only bounds how long
                the request waits for a result. A command stopped this way
                reports `termination_reason` `execution_timeout`.
    SandboxExecResultResponse:
      type: object
      required:
        - request_id
        - execution_id
        - sandbox_id
        - status
        - exit_code
        - stdout
        - stderr
        - stdout_truncated
        - stderr_truncated
        - started_at
        - completed_at
      properties:
        request_id:
          type: string
          description: >-
            Server-generated request ID (`req-<uuid>`), identical to the
            `X-Request-ID` response header.
        execution_id:
          type: string
          format: uuid
        sandbox_id:
          type: string
          description: >-
            Echo of the data-plane addressing key (i.e. `sandbox_key`; the data
            plane identifies the instance by the key in the host).
        status:
          $ref: '#/components/schemas/SandboxExecStatus'
        termination_reason:
          type: string
          enum:
            - explicit_cancel
            - execution_timeout
            - runtime_terminated
          description: >-
            Why an execution that did not finish on its own ended. Omitted when
            the command exited by itself, including when it was killed by a
            signal from inside the sandbox (see exit_code). explicit_cancel: the
            execution was cancelled (status cancelled). execution_timeout: the
            execution reached its timeout (status timed_out).
            runtime_terminated: the command's process is gone without having
            reported an outcome, for example the sandbox was resumed from a
            pause without memory, or its output stream was lost for good, so the
            outcome of the command is unknown (status failed). Pausing a sandbox
            does not by itself end an execution: after a pause with memory the
            command continues and the execution reports its real result.
          example: runtime_terminated
        failure_reason:
          type: string
          enum:
            - cwd_not_found
            - cwd_not_directory
            - permission_denied
          description: >-
            Classified process startup failure. Omitted when no recognized
            startup cause is available. cwd_not_found means the working
            directory does not exist; cwd_not_directory means the working
            directory is not a directory; permission_denied means startup was
            denied without a reliably identified operation. Contains no path or
            raw upstream error. Runtime interruptions use termination_reason.
        exit_code:
          type: integer
          format: int32
          nullable: true
          description: >-
            Exit status of the command. A command killed by a signal (for
            example an out-of-memory kill) reports 128 + signal (137 for
            SIGKILL) with status failed and no termination_reason. Null while
            non-terminal, and when the execution was cancelled, timed out, or
            its runtime was terminated.
        stdout:
          type: string
          nullable: true
          description: >-
            Captured standard output, or null while not yet available. At most 1
            MiB is kept; further output is dropped and `stdout_truncated` is
            true.
        stderr:
          type: string
          nullable: true
          description: >-
            Captured standard error, or null while not yet available. At most 1
            MiB is kept; further output is dropped and `stderr_truncated` is
            true.
        stdout_truncated:
          type: boolean
          nullable: true
        stderr_truncated:
          type: boolean
          nullable: true
        started_at:
          type: string
          format: date-time
          nullable: true
        completed_at:
          type: string
          format: date-time
          nullable: true
    SandboxExecAcceptedResponse:
      type: object
      required:
        - request_id
        - execution_id
        - sandbox_id
        - status
      properties:
        request_id:
          type: string
          description: >-
            Server-generated request ID (`req-<uuid>`), identical to the
            `X-Request-ID` response header.
        execution_id:
          type: string
          format: uuid
          description: Public execution identifier.
        sandbox_id:
          type: string
          description: >-
            Echo of the data-plane addressing key (i.e. `sandbox_key`; the data
            plane identifies the instance by the key in the host).
        status:
          $ref: '#/components/schemas/SandboxExecStatus'
    SandboxExecStatus:
      type: string
      description: >-
        Public lifecycle status of a sandbox execution. `timed_out` means the
        per-command time limit (`execution_timeout_seconds`) was reached and the
        command was terminated (SIGTERM, then SIGKILL after a grace period);
        `exit_code` is then null.
      enum:
        - pending
        - running
        - cancelling
        - succeeded
        - failed
        - cancelled
        - timed_out
    SandboxExecErrorResponse:
      type: object
      description: >-
        Data-plane error body, in the platform error envelope (without
        `trace_id`).
      required:
        - code
        - message
        - request_id
      properties:
        code:
          type: string
          description: >-
            Stable machine-readable error code. A 401 is always
            `Auth.Unauthorized`.
          example: Execution.InvalidRequest
        message:
          type: string
          description: Sanitized human-readable error message.
        request_id:
          type: string
          description: >-
            Server-generated ID for this request (`req-<uuid>`), identical to
            the `X-Request-ID` response header. A caller-supplied `X-Request-ID`
            is not used.
          example: req-3f2b6c1e-8a0d-4f6b-9c3e-2d7a1b5e9f40
        details:
          type: object
          additionalProperties: true
  responses:
    SandboxExecBadRequest:
      description: >-
        Invalid execution request or query parameter. The error code is
        `Execution.InvalidRequest` (invalid body, parameter or header, an
        unknown query parameter, or a request body over 1 MiB),
        `Execution.InvalidWaitTimeout` (`wait_timeout_seconds` outside 1..25) or
        `Execution.IdempotentParameterMismatch` (the `Idempotency-Key` was
        already used with different parameters).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxExecErrorResponse'
    SandboxExecUnauthorized:
      description: >
        Missing or invalid X-Access-Token. The body is always

        `{"code":"Auth.Unauthorized","message":"unauthorized","request_id":"..."}`;
        missing, malformed,

        expired, and wrong-sandbox tokens are indistinguishable.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxExecErrorResponse'
          example:
            code: Auth.Unauthorized
            message: unauthorized
            request_id: req-3f2b6c1e-8a0d-4f6b-9c3e-2d7a1b5e9f40
    SandboxExecRuntimeNotRunning:
      description: >-
        The sandbox is not running, so no command can be executed. The error
        code is `Execution.RuntimeNotRunning`. Start or resume the sandbox and
        retry.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxExecErrorResponse'
    SandboxExecRateLimited:
      description: >-
        The request was rate-limited. For `POST /executions` the code is
        `Execution.ConcurrencyLimitExceeded`: a sandbox allows at most 10
        non-terminal executions at the same time; retry after one completes.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxExecErrorResponse'
    SandboxExecInternalError:
      description: >-
        The execution service failed to complete the request. The error code
        identifies the failing step, for example `Execution.ResultFailed` when
        reading an execution's result fails.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxExecErrorResponse'
    SandboxExecUnavailable:
      description: >-
        A dependency of the execution service is temporarily unavailable; the
        request can be retried. The error code is
        `Execution.ProviderUnavailable` (the sandbox backend could not be
        reached) or `Execution.StoreUnavailable` (the execution record could not
        be read or written).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxExecErrorResponse'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >
        API Key or Access Token, always sent as `Authorization: Bearer <token>`.
        The gateway recognizes the token type automatically.
    sandboxAccessToken:
      type: apiKey
      in: header
      name: X-Access-Token
      description: >
        Sandbox data-plane token — the `sandbox_access_token` returned by the
        create/connect endpoints. Used for `/files`, Sandbox-Exec, and other
        data-plane endpoints; the control plane (`/api/v2`) does not accept it,
        and conversely the control plane's `Authorization: Bearer` is invalid on
        the data plane.


        The token is bound to its sandbox: using sandbox A's token against
        sandbox B's host fails. It stays valid until the sandbox's lifetime
        ends; there is no separate rotation endpoint (`rotate_traffic_token`
        rotates the port traffic token `traffic_access_token` and does not
        affect this one).

````

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