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

# List Sandcastles

> List sandboxes with status filtering and cursor-based pagination

<Note>
  Liveness in list results is eventually consistent — a sandbox that died abruptly may report `running` for a short window (up to \~1 hour). [GET /v2/sandcastles/{id}](/api-reference/v2/sandbox/get-sandbox-status) is the authoritative live check for a single sandbox.
</Note>


## OpenAPI

````yaml GET /v2/sandcastles
openapi: 3.1.0
info:
  title: TextQL v2 API
  version: '2.0'
  description: >
    REST API for TextQL platform operations. All endpoints require Bearer token
    authentication.
servers:
  - url: https://app.textql.com
security:
  - bearerAuth: []
tags:
  - name: Chat
    description: Create and manage AI chat sessions
  - name: Connectors
    description: List available data connectors
  - name: Playbooks
    description: Create, configure, and run automated playbooks
  - name: Sandcastles
    description: Manage Python sandbox environments for code execution
  - name: Changes
    description: Review, approve, and deny Ontology changes
  - name: API Keys
    description: Mint and revoke scoped platform API keys
paths:
  /v2/sandcastles:
    get:
      tags:
        - Sandcastles
      summary: List Sandcastles
      description: |
        List sandboxes for the authenticated organization with cursor-based
        pagination.

        Each item reports a `status`:
        - `running` — a live worker record was seen recently. Liveness is
          eventually consistent: a sandbox that died abruptly may continue to
          report `running` for a short window (up to ~1 hour).
        - `stale` — the lease is open but no live worker record exists; the
          worker is likely gone. Call `DELETE /v2/sandcastles/{id}` (Stop Sandbox)
          to clear it.
        - `unknown` — liveness could not be determined (cache unavailable); the
          lease is open.
        - `stopped` — the sandbox has been released.

        `GET /v2/sandcastles/{id}` is the authoritative live check for a single
        sandbox.
      operationId: v2.listSandboxes
      parameters:
        - name: status
          in: query
          schema:
            type: string
            enum:
              - running
              - stopped
              - all
            default: running
          description: |
            Filter by lease state. `running` (default) returns sandboxes with an
            open lease — individual items may report `running`, `stale`, or
            `unknown`. `stopped` returns released sandboxes. `all` returns both.
        - name: limit
          in: query
          schema:
            type: integer
            format: int32
            minimum: 1
            maximum: 200
            default: 50
          description: Maximum number of sandboxes to return (default 50, max 200)
        - name: cursor
          in: query
          schema:
            type: string
          description: |
            Opaque pagination cursor from a previous response's `next_cursor`.
            Omit to start from the first page.
      responses:
        '200':
          description: Paginated list of sandboxes
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListSandboxesResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  schemas:
    ListSandboxesResponse:
      type: object
      required:
        - sandboxes
      properties:
        sandboxes:
          type: array
          items:
            $ref: '#/components/schemas/SandboxSummary'
        next_cursor:
          type: string
          nullable: true
          description: |
            Opaque cursor to pass as `cursor` on the next request. Omitted when
            there are no more results.
    SandboxSummary:
      type: object
      properties:
        sandbox_id:
          type: string
          description: Unique sandbox identifier
        status:
          type: string
          enum:
            - running
            - stale
            - unknown
            - stopped
          description: |
            Sandbox state:
            - `running` — a live worker record was seen recently. Liveness is
              eventually consistent; a sandbox that died abruptly may report
              `running` for a short window (up to ~1 hour).
            - `stale` — the lease is open but no live worker record exists; the
              worker is likely gone. Call `DELETE /v2/sandcastles/{id}` to clear it.
            - `unknown` — liveness could not be determined (cache unavailable);
              the lease is open.
            - `stopped` — the sandbox has been released.

            Use `GET /v2/sandcastles/{id}` for the authoritative live check of a
            single sandbox.
        member_id:
          type: string
          nullable: true
          description: Member that started the sandbox. Null for legacy/open-lease rows.
        chat_id:
          type: string
          nullable: true
          description: Chat the sandbox is attached to. Null when not attached to a chat.
        started_at:
          type: string
          format: date-time
          description: When the sandbox was started
        released_at:
          type: string
          format: date-time
          nullable: true
          description: When the sandbox was released. Null while the lease is open.
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              description: Machine-readable error code
              enum:
                - invalid_request
                - unauthenticated
                - permission_denied
                - not_found
                - conflict
                - rate_limit_exceeded
                - internal
                - timeout
                - cancelled
                - execution_failed
                - no_report
            message:
              type: string
              description: Human-readable error message
  responses:
    BadRequest:
      description: Invalid request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: invalid_request
              message: Invalid request body
    Unauthorized:
      description: Missing or invalid authentication
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: unauthenticated
              message: Authentication required
    Forbidden:
      description: Insufficient permissions
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: permission_denied
              message: Insufficient permissions
    RateLimited:
      description: Rate limit exceeded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: rate_limit_exceeded
              message: Rate limit exceeded
    InternalError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: internal
              message: Internal server error
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: API key or JWT token

````