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

# Create a sandbox

> Records the sandbox and queues each twin for provisioning. The twins are not serving yet: poll the sandbox until each reports `ready`, then collect its API key.



## OpenAPI

````yaml https://api.twinbay.ai/openapi.json post /sandboxes
openapi: 3.1.0
info:
  title: Twinbay
  description: Backend API
  version: 0.1.0
servers:
  - url: https://api.twinbay.ai
    description: Production
security: []
tags:
  - name: healthchecks
    description: Healthcheck endpoints
  - name: users
    description: >-
      The current user. Sign-up and sign-in happen in WorkOS AuthKit, which
      issues the access tokens this API accepts.
  - name: organizations
    description: >-
      Organizations the caller belongs to. Every authenticated request acts
      inside exactly one organization — the one its access token names — so
      these routes address it as `current`.
  - name: api-keys
    description: >-
      Long-lived credentials for callers that cannot hold an AuthKit session —
      agents, SDKs, CI. A key is accepted wherever an access token is, and acts
      with the role its creator holds when the request arrives.
  - name: sandboxes
    description: >-
      Create and edit isolated provider sandboxes. Each sandbox contains
      behavioural twins from the `twins` package.
  - name: twins
    description: Browse the digital twins available for new sandboxes.
paths:
  /sandboxes:
    post:
      tags:
        - sandboxes
      summary: Create a sandbox
      description: >-
        Records the sandbox and queues each twin for provisioning. The twins are
        not serving yet: poll the sandbox until each reports `ready`, then
        collect its API key.
      operationId: create_sandbox
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateSandboxRequest'
        required: true
      responses:
        '202':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SandboxResponse'
        '401':
          description: The credential is missing, malformed, expired, or not trusted
        '403':
          description: The credential does not act inside an organization
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - Access token: []
        - Organization API key: []
components:
  schemas:
    CreateSandboxRequest:
      properties:
        name:
          type: string
          maxLength: 100
          minLength: 1
          title: Name
          description: Display name of the new sandbox
        prompt:
          anyOf:
            - type: string
              maxLength: 4000
              minLength: 1
            - type: 'null'
          title: Prompt
          description: >-
            A natural-language description of the scenario the whole sandbox
            represents. Every twin in it is seeded from this description while
            it is being provisioned.
        twins:
          anyOf:
            - items:
                $ref: '#/components/schemas/CreateSandboxTwinRequest'
              type: array
              maxItems: 5
              minItems: 1
            - type: 'null'
          title: Twins
          description: >-
            Provider twins to provision in the sandbox. Omitted when the sandbox
            is started from a template, which holds them already.
        template:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Template
          description: >-
            A saved sandbox definition to start from, instead of listing twins.
            Its twins, their curated scenarios and their instructions are used
            as they were saved.
        save_as_template:
          type: boolean
          title: Save As Template
          description: >-
            Also save this sandbox's definition, so another sandbox can be
            started from it later.
          default: false
      additionalProperties: false
      type: object
      required:
        - name
      title: CreateSandboxRequest
    SandboxResponse:
      properties:
        id:
          type: string
          format: uuid
          title: Id
        slug:
          type: string
          title: Slug
        name:
          type: string
          title: Name
        status:
          type: string
          title: Status
        twins:
          items:
            $ref: '#/components/schemas/SandboxTwinResponse'
          type: array
          title: Twins
        created_at:
          type: string
          format: date-time
          title: Created At
        expires_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Expires At
      type: object
      required:
        - id
        - slug
        - name
        - status
        - twins
        - created_at
      title: SandboxResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    CreateSandboxTwinRequest:
      properties:
        twin:
          type: string
          maxLength: 100
          minLength: 1
          title: Twin
          description: Slug of the twin to serve
        scenario_template:
          anyOf:
            - type: string
              maxLength: 100
              minLength: 1
            - type: 'null'
          title: Scenario Template
          description: A curated scenario offered by the selected twin.
        prompt:
          anyOf:
            - type: string
              maxLength: 4000
              minLength: 1
            - type: 'null'
          title: Prompt
          description: >-
            What this twin adds to the sandbox's instruction, for a provider
            that needs a note of its own. It is appended to the sandbox
            instruction rather than replacing it.
      additionalProperties: false
      type: object
      required:
        - twin
      title: CreateSandboxTwinRequest
    SandboxTwinResponse:
      properties:
        id:
          type: string
          format: uuid
          title: Id
        twin_slug:
          type: string
          title: Twin Slug
        twin_version:
          anyOf:
            - type: string
            - type: 'null'
          title: Twin Version
          description: The release the current container was started from.
        desired_state:
          type: string
          title: Desired State
          description: running or stopped
        state:
          type: string
          title: State
          description: >-
            What the twin is actually doing: pending, provisioning, starting,
            ready, stopping, stopped or failed.
        url:
          type: string
          title: Url
        failure:
          anyOf:
            - type: string
            - type: 'null'
          title: Failure
          description: Why the current run is not serving, if it is not.
        created_at:
          type: string
          format: date-time
          title: Created At
        ready_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Ready At
      type: object
      required:
        - id
        - twin_slug
        - desired_state
        - state
        - url
        - created_at
      title: SandboxTwinResponse
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    Access token:
      type: http
      description: Access token issued by WorkOS AuthKit.
      scheme: bearer
    Organization API key:
      type: apiKey
      description: >-
        An organization API key, as minted by POST
        /organizations/current/api-keys.
      in: header
      name: X-API-Key

````