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

# Get preview URL

> Get a public HTTPS URL for a port inside a sandbox with the Brimble Sandboxes API.

Returns a public HTTPS URL that routes to `port` inside the sandbox. No expose step is needed, and the URL stays the same for a given sandbox and port.

The URL serves traffic while the sandbox is running and a process listens on that port. Bind your server to `0.0.0.0`, not `localhost`. If the sandbox is paused or destroyed, the URL responds with a "not running" page.

SDKs: `handle.getPreviewUrl(port)` (TypeScript), `sandbox.get_preview_url(port)` (Python), `handle.GetPreviewURL(ctx, port)` (Go).


## OpenAPI

````yaml GET /sandboxes/{id}/ports/{port}/preview-url
openapi: 3.0.3
info:
  title: Brimble Sandbox API
  description: >
    REST API for managing Brimble sandboxes, ephemeral compute environments with

    optional persistent storage. Covers lifecycle (create / pause / resume /
    destroy),

    egress policy, runtime operations (exec, runCode, file upload/download),

    observability (logs, stats), and snapshots.


    ## Conventions


    - **Response envelope:** non-`204` JSON responses use `{ "message": string,
    "data"?: <payload> }`.
      The schemas below describe the **`data`** payload only.
    - **Errors:** every non-2xx response uses `{ "message": string }`. The
    message is
      user-facing.
    - **Async transitions:** pause / resume / destroy return immediately;
      the status change is visible on the next `GET` or in the dashboard.
      **Create is synchronous** — `POST /sandboxes` blocks until `status` is `ready`.
    - **IDs:** every `id` is a 24-char hex string.
  version: 1.0.0
  contact:
    name: Brimble Engineering
    url: https://brimble.io
servers:
  - url: https://sandbox.brimble.io
    description: Production
security:
  - brimbleKey: []
tags:
  - name: Sandboxes
    description: Lifecycle and metadata
  - name: Runtime
    description: Exec, code, files
  - name: Observability
    description: Logs and stats
  - name: Snapshots
    description: Manual & automatic snapshots
  - name: Volumes
    description: >-
      Persistent disks, pre-provisioned independently of sandbox lifecycle, then
      attached to a sandbox or project
paths:
  /sandboxes/{id}/ports/{port}/preview-url:
    get:
      tags:
        - Sandboxes
      summary: Get a preview URL for a port
      description: >
        Returns a public HTTPS URL that routes to the given port inside the
        sandbox.

        There is no expose step: any port works, and the URL is stable for a
        given

        sandbox and port. Traffic is served while the sandbox is running and a

        process listens on that port (bind to `0.0.0.0`).
      operationId: getSandboxPreviewUrl
      parameters:
        - $ref: '#/components/parameters/SandboxIdParam'
        - name: port
          in: path
          required: true
          description: Port inside the sandbox, 1 to 65535.
          schema:
            type: integer
            minimum: 1
            maximum: 65535
          example: 5173
      responses:
        '200':
          description: Preview URL
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SandboxPreviewEnvelope'
              examples:
                vite:
                  summary: Dev server on port 5173
                  value:
                    message: Sandbox preview URL fetched
                    data:
                      port: 5173
                      url: https://0k3n5q2v8x1m4p7r9t2w6y0za.brimble.run
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          $ref: '#/components/responses/NotFound'
        '503':
          description: Sandbox previews are not available right now
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  parameters:
    SandboxIdParam:
      in: path
      name: id
      required: true
      schema:
        type: string
        pattern: ^[a-f0-9]{24}$
      description: 24-char hex id of the sandbox.
  schemas:
    SandboxPreviewEnvelope:
      type: object
      required:
        - message
        - data
      properties:
        message:
          type: string
          example: Sandbox preview URL fetched
        data:
          type: object
          required:
            - port
            - url
          properties:
            port:
              type: integer
              example: 5173
            url:
              type: string
              format: uri
              example: https://0k3n5q2v8x1m4p7r9t2w6y0za.brimble.run
    ErrorResponse:
      type: object
      required:
        - message
      properties:
        message:
          type: string
          description: Human-readable, user-facing error reason.
  responses:
    BadRequest:
      description: Validation error / invalid state transition
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            invalidId:
              summary: Invalid sandbox id
              value:
                message: Invalid sandbox id
            statusTransition:
              summary: Wrong status
              value:
                message: Sandbox is paused; only ready sandboxes can be paused
            fileNotDir:
              summary: Parent dir missing on upload
              value:
                message: 'Destination directory does not exist: /work'
            duplicateVolumeName:
              summary: Duplicate volume name
              value:
                message: A volume named "node-cache" already exists
            volumeAttached:
              summary: Delete attempted on attached volume
              value:
                message: Volume is attached; detach it before deleting
    NotFound:
      description: >-
        Sandbox or related resource not found (also returned when owned by
        another user)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            sandboxNotFound:
              value:
                message: Sandbox not found
            snapshotNotFound:
              value:
                message: Snapshot not found
            volumeNotFound:
              value:
                message: Volume not found
  securitySchemes:
    brimbleKey:
      type: apiKey
      in: header
      name: x-brimble-key
      description: |
        Your account-level Brimble API key. Find it in the dashboard under
        your profile drawer → **API key** (click the avatar in the sidebar).
        Available on paid plans only.

````

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