> ## 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.

# Cancel a sandbox execution

> Requests cancellation of a non-terminal execution. The call returns `202` once cancellation is accepted; the execution then moves to `cancelling` and finally `cancelled`. Cancellation is not idempotent: cancelling an execution that is already cancelled, being cancelled, or finished returns `409` (`Execution.AlreadyCancelled`, `Execution.CancelInProgress` or `Execution.AlreadyCompleted`).

The request must have an empty body; any non-empty body returns 400 `Execution.InvalidRequest`.




## OpenAPI

````yaml /api-spec/sandbox_api.yaml post /executions/{execution_id}/cancel
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/{execution_id}/cancel:
    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: Cancel a sandbox execution
      description: >
        Requests cancellation of a non-terminal execution. The call returns
        `202` once cancellation is accepted; the execution then moves to
        `cancelling` and finally `cancelled`. Cancellation is not idempotent:
        cancelling an execution that is already cancelled, being cancelled, or
        finished returns `409` (`Execution.AlreadyCancelled`,
        `Execution.CancelInProgress` or `Execution.AlreadyCompleted`).


        The request must have an empty body; any non-empty body returns 400
        `Execution.InvalidRequest`.
      operationId: cancelSandboxExecution
      parameters:
        - $ref: '#/components/parameters/SandboxExecExecutionIDParam'
        - $ref: '#/components/parameters/SandboxExecRequestIDParam'
      responses:
        '202':
          description: Cancellation accepted and is being processed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SandboxExecAcceptedResponse'
        '400':
          description: >-
            The request carries a body. This endpoint takes none: any non-empty
            request body, whatever its `Content-Type`, is rejected with
            `Execution.InvalidRequest`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SandboxExecErrorResponse'
        '401':
          $ref: '#/components/responses/SandboxExecUnauthorized'
        '404':
          $ref: '#/components/responses/SandboxExecNotFound'
        '409':
          $ref: '#/components/responses/SandboxExecConflict'
        '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:
    SandboxExecExecutionIDParam:
      name: execution_id
      in: path
      required: true
      description: >-
        Public execution identifier returned by the create operation. A value
        that is not a valid UUID is treated as an unknown execution and returns
        404 `Execution.NotFound`.
      schema:
        type: string
        format: uuid
    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
  schemas:
    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'
    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
    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
  responses:
    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
    SandboxExecNotFound:
      description: >-
        Execution does not exist, is not owned by this sandbox, or the
        identifier is not a valid UUID.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxExecErrorResponse'
    SandboxExecConflict:
      description: >-
        The execution cannot be cancelled in its current state
        (`Execution.AlreadyCancelled`, `Execution.CancelInProgress` or
        `Execution.AlreadyCompleted`), or the sandbox is not running
        (`Execution.RuntimeNotRunning`).
      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.