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

# Download a sandbox file

> Reads a single file inside the sandbox by absolute path; the response body is the raw byte stream.

## Three ways this differs from the rest of the platform

1. **Not served under `/api/v2`** — see this operation's `servers`.
2. **The auth header is `X-Access-Token`** (the `sandbox_access_token` value), not `Authorization: Bearer`. Control-plane tokens are invalid here, and vice versa.
3. **Successful responses are not wrapped in the `{request_id, data}` envelope** (the body is a byte stream); errors use the `{code, message, request_id}` error body — see the error notes below.

## Optional capabilities: `Content-Length` and resumable downloads

Both **vary by data center; clients must not assume they exist**:

| Capability | When supported | When not supported |
| --- | --- | --- |
| `Accept-Ranges` | `bytes` | `none` |
| `Content-Length` | Declares the byte count; enables progress display | Absent; `Transfer-Encoding: chunked` |
| `Range` requests | Returns `206` + `Content-Range` per RFC 7233 | **Returns `200` with the full file** |

**`Accept-Ranges` is the only runtime capability probe**: issue one request without `Range`, or read the header on the first response, before deciding whether to resume.

Data centers without resume support **never fake a `206`**: a request with `Range` gets `200` and the entire file. This is deliberate — a client that mistakes the response for a range would write bytes at the wrong offset and produce a silently corrupted file, which is far worse than an ignored `Range`. The correct resumable-download logic is therefore "resume only when `Accept-Ranges: bytes`, otherwise re-download the whole file" — **never** key off any signal other than `206`.

The server returns no checksum headers (neither backend provides them); clients that need integrity verification should compute and compare checksums themselves.




## OpenAPI

````yaml /api-spec/sandbox_api.yaml get /files
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:
  /files:
    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.
    get:
      tags:
        - Sandbox-Files
      summary: Download a sandbox file
      description: >
        Reads a single file inside the sandbox by absolute path; the response
        body is the raw byte stream.


        ## Three ways this differs from the rest of the platform


        1. **Not served under `/api/v2`** — see this operation's `servers`.

        2. **The auth header is `X-Access-Token`** (the `sandbox_access_token`
        value), not `Authorization: Bearer`. Control-plane tokens are invalid
        here, and vice versa.

        3. **Successful responses are not wrapped in the `{request_id, data}`
        envelope** (the body is a byte stream); errors use the `{code, message,
        request_id}` error body — see the error notes below.


        ## Optional capabilities: `Content-Length` and resumable downloads


        Both **vary by data center; clients must not assume they exist**:


        | Capability | When supported | When not supported |

        | --- | --- | --- |

        | `Accept-Ranges` | `bytes` | `none` |

        | `Content-Length` | Declares the byte count; enables progress display |
        Absent; `Transfer-Encoding: chunked` |

        | `Range` requests | Returns `206` + `Content-Range` per RFC 7233 |
        **Returns `200` with the full file** |


        **`Accept-Ranges` is the only runtime capability probe**: issue one
        request without `Range`, or read the header on the first response,
        before deciding whether to resume.


        Data centers without resume support **never fake a `206`**: a request
        with `Range` gets `200` and the entire file. This is deliberate — a
        client that mistakes the response for a range would write bytes at the
        wrong offset and produce a silently corrupted file, which is far worse
        than an ignored `Range`. The correct resumable-download logic is
        therefore "resume only when `Accept-Ranges: bytes`, otherwise
        re-download the whole file" — **never** key off any signal other than
        `206`.


        The server returns no checksum headers (neither backend provides them);
        clients that need integrity verification should compute and compare
        checksums themselves.
      operationId: downloadSandboxFile
      parameters:
        - $ref: '#/components/parameters/SandboxFilePathQueryParam'
        - $ref: '#/components/parameters/SandboxFileUsernameQueryParam'
        - name: Range
          in: header
          required: false
          description: >
            Only honored in data centers with `Accept-Ranges: bytes`; format
            `bytes=<start>-<end>`. Other data centers ignore the header and
            return `200` + the full file (not `206`).
          schema:
            type: string
          example: bytes=1048576-
      responses:
        '200':
          description: >
            The full file. Requests with `Range` also take this branch when the
            data center does not support resuming.
          headers:
            Content-Disposition:
              description: >-
                `inline` or `attachment` (depends on the data center), followed
                by `filename=<basename>`. The filename is quoted when it
                contains special characters and is sent as
                `filename*=UTF-8''...` when it is not ASCII.
              schema:
                type: string
            Accept-Ranges:
              description: '`bytes` (resume supported) or `none` (not supported).'
              schema:
                type: string
                enum:
                  - bytes
                  - none
            Content-Length:
              description: >
                **Optional.** Present only in data centers that know the file
                size up front; when absent the response is chunked.
              schema:
                type: integer
                format: int64
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
        '206':
          description: >
            **Optional capability.** Returned only by data centers with
            `Accept-Ranges: bytes`; a request with `Range` may still get `200`,
            and clients must handle whichever status code actually arrives.
          headers:
            Content-Range:
              description: '`bytes <start>-<end>/<total>`'
              schema:
                type: string
            Content-Length:
              description: Byte count of this range
              schema:
                type: integer
                format: int64
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
        '400':
          $ref: '#/components/responses/SandboxFileBadRequest'
        '401':
          $ref: '#/components/responses/SandboxFileUnauthorized'
        '403':
          $ref: '#/components/responses/SandboxFileForbidden'
        '404':
          $ref: '#/components/responses/SandboxFileNotFound'
        '406':
          description: >-
            `Parameter.Invalid`: the data center cannot serve the file in the
            requested `Accept-Encoding`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SandboxFileError'
        '409':
          $ref: '#/components/responses/SandboxFileConflict'
        '412':
          $ref: '#/components/responses/SandboxFilePreconditionFailed'
        '416':
          description: >
            `Parameter.Invalid`. **Optional capability**, returned only by data
            centers that support resuming: the `Range` start is beyond the file
            length.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SandboxFileError'
        '429':
          $ref: '#/components/responses/SandboxFileRateLimited'
        '500':
          $ref: '#/components/responses/SandboxFileInternalError'
        '502':
          $ref: '#/components/responses/SandboxFileUpstreamError'
      security:
        - sandboxAccessToken: []
components:
  parameters:
    SandboxFilePathQueryParam:
      name: path
      in: query
      required: true
      description: >
        **Absolute path** inside the sandbox. Must start with `/` and be
        normalized: relative segments such as `.` / `..` and `//` are rejected,
        and a path that points to a directory (for example one ending in `/`)
        returns `400`. No semantic interpretation is applied beyond existence
        checks; for writes, the parent directory must already exist.
      schema:
        type: string
        minLength: 1
      example: /home/user/data.bin
    SandboxFileUsernameQueryParam:
      name: username
      in: query
      required: false
      description: >
        Perform the file operation as this user; defaults to the sandbox's
        default user. **Optional capability**: some data centers ignore this
        parameter and always act as the default user, so do not rely on it for
        permission isolation.
      schema:
        type: string
      example: user
  responses:
    SandboxFileBadRequest:
      description: >
        `Parameter.Invalid`: invalid request — `path` is missing or (in some
        data centers) repeated in the query or sent as a body form field, is not
        an absolute path, is not normalized (contains `.`, `..` or `//`), points
        to a directory, `username` names a user that does not exist, or the
        upload is malformed.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxFileError'
    SandboxFileUnauthorized:
      description: >
        `Auth.Unauthorized`: `X-Access-Token` is missing, malformed, expired, or
        does not belong to this sandbox.


        **All of these cases return exactly the same code and message**, so they
        cannot be told apart.

        This is deliberate: distinguishable errors would let callers use this
        endpoint as a sandbox-existence

        probe.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxFileError'
          example:
            code: Auth.Unauthorized
            message: unauthorized
            request_id: req-3f2b6c1e-8a0d-4f6b-9c3e-2d7a1b5e9f40
    SandboxFileForbidden:
      description: >-
        `Auth.Forbidden`: the token is valid, but file permissions inside the
        sandbox do not allow the operation.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxFileError'
    SandboxFileNotFound:
      description: >
        `Resource.NotFound`: the target file or its parent directory does not
        exist, or the sandbox is no longer available (deleted/stopped). These
        cases are likewise not distinguished.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxFileError'
    SandboxFileConflict:
      description: >-
        `Resource.StateConflict`: the sandbox is changing state (for example,
        resuming), or the request conflicts with a concurrent operation on the
        same file. Retry later.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxFileError'
    SandboxFilePreconditionFailed:
      description: >-
        `Resource.StateConflict`: a conditional request header (such as
        `If-Match`) does not match the file's current state.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxFileError'
    SandboxFileRateLimited:
      description: '`RateLimit.Exceeded`: data-plane rate limit hit; back off and retry.'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxFileError'
    SandboxFileInternalError:
      description: '`System.Internal`: data-plane internal error.'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxFileError'
    SandboxFileUpstreamError:
      description: >
        `System.Internal`: the data plane's own backend call failed. **This is a
        server-side problem, not a caller credential problem** — re-fetching the
        token will not help; back off and retry, or report it.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxFileError'
  schemas:
    SandboxFileError:
      type: object
      description: >
        Data-plane error body, in the platform error envelope (without
        `trace_id`). Branch on `code`;

        `message` is for humans only — its wording is not a contract and must
        not be used in program logic.


        `code` uses the platform-wide error codes: `Parameter.Invalid`
        (400/405/406/413/415/416),

        `Auth.Unauthorized` (401), `Auth.Forbidden` (403), `Resource.NotFound`
        (404),

        `Resource.StateConflict` (409/412), `RateLimit.Exceeded` (429), and
        `System.Internal` (5xx).


        `message` is always the server's own wording: raw backend error text may
        contain internal details

        such as absolute paths inside the sandbox, so it is logged only and
        never returned.
      required:
        - code
        - message
        - request_id
      properties:
        code:
          type: string
          description: Stable machine-readable error code.
          example: Resource.NotFound
        message:
          type: string
          description: Human-readable error text. Not stable; do not parse.
          example: file not found
        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
  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.