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

# Update sandbox metadata

> Replaces the customer-defined metadata as a whole — no per-key merging; passing an empty object clears it. There are no mutable fields other than `metadata`. This operation does not take the lifecycle lock, so it works in any state except `deleting` and `deleted`, for which it returns 404.




## OpenAPI

````yaml /api-spec/sandbox_api.yaml patch /sandboxes/{id}
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:
  /sandboxes/{id}:
    patch:
      tags:
        - Sandbox
      summary: Update sandbox metadata
      description: >
        Replaces the customer-defined metadata as a whole — no per-key merging;
        passing an empty object clears it. There are no mutable fields other
        than `metadata`. This operation does not take the lifecycle lock, so it
        works in any state except `deleting` and `deleted`, for which it returns
        404.
      operationId: updateSandbox
      parameters:
        - $ref: '#/components/parameters/SandboxIdPathParam'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateSandboxControlRequest'
      responses:
        '200':
          description: Update succeeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SandboxControlDetailResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '499':
          $ref: '#/components/responses/RequestCanceled'
        '500':
          $ref: '#/components/responses/InternalError'
        '504':
          $ref: '#/components/responses/RequestTimeout'
components:
  parameters:
    SandboxIdPathParam:
      name: id
      in: path
      required: true
      description: >-
        Unique sandbox resource ID (UUID; the `id` field of the create
        response). The data-plane key (`sandbox_key`) cannot be used here.
      schema:
        type: string
        format: uuid
      example: 3f6f0d3e-6f0a-4a2e-9c58-0d3e6f0a4a2e
  schemas:
    UpdateSandboxControlRequest:
      type: object
      required:
        - metadata
      properties:
        metadata:
          type: object
          additionalProperties:
            type: string
          description: Customer metadata, replaced as a whole.
    SandboxControlDetailResponse:
      type: object
      required:
        - request_id
        - data
      properties:
        request_id:
          type: string
          description: Request tracing ID
        data:
          $ref: '#/components/schemas/SandboxControlDetail'
    SandboxControlDetail:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: >-
            Unique sandbox resource ID (UUID), used both in control-plane path
            parameters and as the billing resource_id.
        sandbox_key:
          type: string
          description: >
            Data-plane addressing key (an `i` followed by a 20-character random
            string). Used solely to assemble data-plane URLs:
            `https://{sandbox_key}.{domain}` and
            `https://{port}-{sandbox_key}.{domain}`. Control-plane endpoints
            always use `id` and do not accept this field.
        template_id:
          type: string
        snapshot_id:
          type: string
          description: >-
            Durable snapshot used to create this sandbox; omitted for
            template-created sandboxes.
        idc_name:
          type: string
        state:
          $ref: '#/components/schemas/SandboxControlState'
        product:
          type: string
          description: Catalog SKU of the preset the resource was created from.
        product_name:
          type: string
          description: Human-readable label of the preset the resource was created from.
        resources:
          $ref: '#/components/schemas/SandboxResources'
        metadata:
          type: object
          additionalProperties:
            type: string
          description: >-
            Customer-defined key/value pairs; the platform does not interpret
            them. The list endpoint can filter by them.
        latest_operation:
          $ref: '#/components/schemas/SandboxMutationResult'
        failure:
          $ref: '#/components/schemas/SandboxFailure'
        created_at:
          type: string
          description: Time the request was accepted, UTC
        running_at:
          type: string
          description: >-
            Time the instance was confirmed running; empty string while not yet
            running
        started_at:
          type: string
          description: UTC timestamp, e.g. 2026-08-04T09:12:31.123456789Z
        end_at:
          type: string
          description: >
            UTC timestamp; the expiry time of the runtime budget. A pause does
            not consume runtime, so this field is frozen while `paused` (and may
            therefore already be in the past) and is shifted forward by the
            paused duration on resume. The runtime left on a paused instance is
            `end_at - paused_at`, not `end_at - now`.
        paused_at:
          type: string
          description: >
            Time the instance entered `paused` (UTC), and the baseline the
            runtime budget is frozen against. Returned while `paused` and
            `resuming`; cleared once a resume is confirmed `running`.
        paused_expire_at:
          type: string
          description: >
            End of the pause retention window (UTC). Returned while `paused` and
            `resuming`; cleared once a resume is confirmed `running`. An
            instance not resumed by then is reclaimed together with its disk.
            This is a separate budget from `end_at` — this one bounds how long
            an instance may stay paused, `end_at` how long it may run.
        pause:
          type: object
          description: >
            Why the instance is paused. Returned while `pausing`, `paused` and
            `resuming`; cleared once a resume is confirmed `running`. A pause
            you requested and a pause the platform applied look the same
            otherwise; `code` tells them apart, and
            `Sandbox.BillingInsufficientBalance` means the sandbox stays paused
            until the account is topped up and the sandbox is resumed.
          required:
            - code
            - initiator
            - message
            - requested_at
          properties:
            code:
              type: string
              description: >
                `Sandbox.UserPaused`: paused through `POST
                /sandboxes/{id}/pause`. `Sandbox.BillingInsufficientBalance`:
                paused by the platform because the account balance is
                insufficient. `Sandbox.Expired`: paused automatically when the
                runtime budget ran out (`lifecycle.on_timeout=pause`).
              example: Sandbox.BillingInsufficientBalance
            initiator:
              type: string
              enum:
                - user
                - billing
                - lifecycle
            message:
              type: string
              description: Fixed customer-facing text for `code`.
            requested_at:
              type: string
              description: >
                When the pause was requested (UTC). Distinct from `paused_at`,
                which is the baseline the runtime budget is frozen against.
        domain:
          type: string
        deletion:
          $ref: '#/components/schemas/SandboxDeletion'
        lifecycle:
          $ref: '#/components/schemas/SandboxControlLifecycle'
        egress_control:
          type: boolean
          description: >-
            Whether dedicated egress control was enabled for this sandbox at
            creation.
        egress:
          $ref: '#/components/schemas/SandboxEgressPolicy'
    ErrorResponse:
      type: object
      required:
        - code
        - message
        - request_id
      properties:
        code:
          type: string
          description: Machine-readable business error code
          example: Resource.QuotaExceeded
        message:
          type: string
          description: Human-readable error description
          example: The resource quota is not enough.
        request_id:
          type: string
          description: Tracing ID
          example: req-xxxx
        trace_id:
          type: string
          description: >-
            Server-side trace identifier for this request; quote it when
            reporting a problem.
        details:
          type: object
          description: Field-level error details
          additionalProperties: true
    SandboxControlState:
      type: string
      description: >
        External lifecycle state. The internal `creating` state is expressed
        externally as `provisioning` (the instance is being prepared and is not
        usable yet); backend queueing is not expressed separately and is also
        folded into `provisioning`.


        `deleting` / `deleted`: deletion is a soft delete - once accepted the
        instance enters `deleting`, and after the backing resources are
        confirmed released it reaches the terminal `deleted` state, whose record
        is kept permanently. In both states the detail endpoint still returns
        200 and the `deletion` object says who initiated the deletion and why;
        the data plane returns 404 for them, as do PATCH, connect, pause, resume
        and timeout; `/actions` returns 409, or 400 when the sandbox was created
        without `egress_control`. DELETE can be repeated: it returns 202 while
        `deleting` and 200 once `deleted`. The default list excludes both
        states, and `state=deleted` returns deleted records explicitly.


        `pausing` / `paused` / `resuming`: pause and resume are an explicit pair
        of lifecycle operations (see `POST /sandboxes/{id}/pause` and `POST
        /sandboxes/{id}/resume`); both return 202 on acceptance and the settled
        outcome is read back from this field. `pausing` and `resuming` are
        transitional. `paused` means the disk is retained and the instance is no
        longer running, and no longer consuming its runtime budget either
        (`end_at` is frozen and may already be in the past); it is reclaimed at
        the end of the retention window `paused_expire_at`.
      enum:
        - provisioning
        - running
        - pausing
        - paused
        - resuming
        - checkpointing
        - updating
        - failed
        - deleting
        - deleted
    SandboxResources:
      type: object
      description: >-
        Compute resources. Fixed when the Template Build is created and
        snapshotted at sandbox creation; immutable afterwards, and the create
        request cannot override them.
      properties:
        vcpu:
          type: integer
          format: int64
        memory_mb:
          type: integer
          format: int64
        disk_mb:
          type: integer
          format: int64
    SandboxMutationResult:
      type: object
      description: >
        The most recent operation and its outcome. status=pending means the
        command has been accepted but the outcome has not settled yet
        (asynchronous creation and deletion are in this state right after
        acceptance).
      required:
        - type
        - status
      properties:
        type:
          type: string
          enum:
            - create
            - delete
            - set_timeout
            - update_egress_policy
            - update_ingress_policy
            - rotate_traffic_token
        status:
          type: string
          enum:
            - pending
            - succeeded
            - failed
        error_code:
          type: string
          example: invalid_argument
        message:
          type: string
          description: Sanitized failure reason; never contains access tokens
        completed_at:
          type: string
          format: date-time
    SandboxFailure:
      type: object
      description: >-
        Non-empty only when state=failed. The message is sanitized and contains
        no backend identifiers or internal host addresses.
      properties:
        code:
          type: string
          example: Parameter.Invalid
        message:
          type: string
        occurred_at:
          type: string
    SandboxDeletion:
      type: object
      description: >-
        Present only when `state` is `deleting` or `deleted`; explains who
        initiated the deletion and why. `message` is a fixed text for `code`;
        raw billing or backend error text is never exposed.
      required:
        - code
        - initiator
        - message
        - requested_at
        - completed_at
      properties:
        code:
          type: string
          description: >-
            Deletion reason code. `Sandbox.UserDeleted`: deleted by the user.
            `Sandbox.BillingInsufficientBalance`, `Sandbox.BillingNoPermission`,
            `Sandbox.BillingProductNotFound`,
            `Sandbox.BillingOrderCreateFailed`: billing order creation failed.
            `Sandbox.BillingSuspended`: stopped for non-payment.
            `Sandbox.Expired`: reclaimed at expiry. `Sandbox.ProvisionTimedOut`,
            `Sandbox.ProvisionFailed`: creation did not become ready.
            `Sandbox.ResumeTimedOut`, `Sandbox.PauseFailed`: reclaimed after a
            stuck pause or resume. `Sandbox.ProviderGone`: the backing instance
            no longer exists. `Sandbox.Unknown`: reason not recorded.
          example: Sandbox.UserDeleted
        initiator:
          type: string
          enum:
            - user
            - billing
            - lifecycle
            - system
          description: >-
            Who initiated the deletion - the user, billing, the lifecycle (TTL
            expiry), or the platform.
        message:
          type: string
          description: Fixed user-facing text.
        requested_at:
          type: string
          description: >-
            When the deletion intent was accepted (UTC); also the end point of
            billing metering.
        completed_at:
          type: string
          nullable: true
          description: >-
            When the release was confirmed and the sandbox became `deleted`
            (UTC); null while `deleting`.
    SandboxControlLifecycle:
      type: object
      required:
        - auto_resume
        - on_timeout
      properties:
        auto_resume:
          type: boolean
        on_timeout:
          type: string
          enum:
            - pause
            - kill
          description: >-
            What happens when the sandbox runtime budget runs out. `pause`
            pauses the sandbox (see `auto_pause` on create); `kill` deletes it.
    SandboxEgressPolicy:
      type: object
      additionalProperties: false
      properties:
        allowed_hostnames:
          type: array
          items:
            type: string
          description: Allowed hostnames; a leading `*.` wildcard is supported.
        allowed_cidrs:
          type: array
          items:
            type: string
          description: Allowed IPv4 CIDRs.
  responses:
    BadRequest:
      description: >-
        Invalid request parameters. Two code families are used:
        `Request.InvalidParameter` for request parsing and format validation
        (unknown or malformed body fields, malformed IDs, invalid enum values,
        out-of-range paging) and `Parameter.Invalid` for business validation
        (for example a template or IDC that cannot be found, or a `timeout` over
        the limit). Unknown or invalid fields inside the `params` of `POST
        /sandboxes/{id}/actions` are reported as `Parameter.Invalid`. Other 400
        codes are specific to an operation, for example `Sandbox.SourceConflict`
        (both or neither of `template_id` and `snapshot_id`) and
        `Sandbox.IdempotentParameterMismatch` (an `Idempotency-Key` reused with
        different parameters). Both code families share the same HTTP status, so
        decide by the `code` value, not the status alone.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: Parameter.Invalid
            message: Invalid request parameters
            request_id: req-xxxx
    Unauthorized:
      description: Unauthenticated
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: Auth.Unauthorized
            message: Authentication required
            request_id: req-xxxx
    Forbidden:
      description: The caller cannot access the organization-scoped resource.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: Resource.NotFound
            message: The requested resource was not found
            request_id: req-xxxx
    RequestCanceled:
      description: The caller canceled the current HTTP request.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: Request.Canceled
            message: Request canceled
            request_id: req-xxxx
    InternalError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: System.Internal
            message: An internal server error occurred
            request_id: req-xxxx
    RequestTimeout:
      description: The current HTTP request exceeded the control-plane processing deadline.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: Request.Timeout
            message: Request timed out
            request_id: req-xxxx
  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.

````

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