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

# Rebuild an existing template

> Queues a new build for this template. Used to retry after a failed
build, or to rebuild when the base image has been updated.

The **first** build is queued automatically when the template is
created via `POST /templates` — this endpoint is only for
subsequent builds.

## Idempotency

If an in-flight build (`pending`/`building`/`snapshotting`) already
exists for this template with the same build spec, this endpoint
returns the existing build's id with `200` instead of creating a
duplicate.




## OpenAPI

````yaml https://raw.githubusercontent.com/superserve-ai/sandbox/refs/heads/main/api/openapi.yaml post /templates/{template_id}/builds
openapi: 3.1.0
info:
  title: Superserve API
  version: 0.1.0
  description: >
    Superserve provides sandbox infrastructure to run AI agents in the cloud.
    Powered by Firecracker MicroVMs.


    ## Sandbox lifecycle


    ```

    active <--> paused --> deleted

    ```


    A sandbox is `active` when running and `paused` after being paused. Resuming

    a paused sandbox returns it to `active`. Deleting releases all resources.


    | Endpoint | What it does |

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

    | `POST /sandboxes` | Create a new sandbox (optionally `from_template`) |

    | `PATCH /sandboxes/:id` | Partially update a running sandbox (e.g. network
    rules) |

    | `POST /sandboxes/:id/pause` | Snapshot full state, suspend the VM |

    | `POST /sandboxes/:id/resume` | Restore from snapshot, continue where it
    left off |

    | `DELETE /sandboxes/:id` | Delete sandbox and all resources |


    ## Sandbox environment


    By default sandboxes boot from the curated `superserve/base` template
    (Ubuntu 24.04,

    1 vCPU, 1 GB RAM, 4 GB disk, with Python 3.12, Node.js 22, npm, git, curl,

    and build-essential pre-installed). Callers can override with any template

    name (e.g. `superserve/python-3.11`, `superserve/node-22`) or a team-owned
    template UUID

    via the `from_template` field on `POST /sandboxes`.


    ## Files and commands


    `/files`, `/exec`, and `/exec/stream` run against a single sandbox and use

    its `X-Access-Token` (returned by create, resume, and activate), not the

    team API key. Two host forms reach them:


    - `https://sandbox.superserve.ai/...` with `X-Superserve-Sandbox-Id:
    <sandbox_id>`.

    - `https://boxd-{sandbox_id}.sandbox.superserve.ai/...` — no routing header
    needed.
  contact:
    name: Superserve Team
  license:
    name: Proprietary
servers:
  - url: https://api.superserve.ai
    description: Production
security: []
paths:
  /templates/{template_id}/builds:
    parameters:
      - $ref: '#/components/parameters/TemplateId'
    post:
      tags:
        - Templates
      summary: Rebuild an existing template
      description: |
        Queues a new build for this template. Used to retry after a failed
        build, or to rebuild when the base image has been updated.

        The **first** build is queued automatically when the template is
        created via `POST /templates` — this endpoint is only for
        subsequent builds.

        ## Idempotency

        If an in-flight build (`pending`/`building`/`snapshotting`) already
        exists for this template with the same build spec, this endpoint
        returns the existing build's id with `200` instead of creating a
        duplicate.
      operationId: createTemplateBuild
      responses:
        '200':
          description: Existing in-flight build returned (idempotent)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TemplateBuildResponse'
        '201':
          description: Build created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TemplateBuildResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '429':
          description: >
            Team has reached the per-team concurrent build limit. Response body
            uses error code `too_many_builds`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          $ref: '#/components/responses/InternalError'
      security:
        - apiKey: []
components:
  parameters:
    TemplateId:
      name: template_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: The unique identifier of the template.
  schemas:
    TemplateBuildResponse:
      type: object
      properties:
        id:
          type: string
          format: uuid
        template_id:
          type: string
          format: uuid
        status:
          type: string
          enum:
            - pending
            - building
            - snapshotting
            - ready
            - failed
            - cancelled
        build_spec_hash:
          type: string
          description: >-
            Stable hash of the build_spec at submission time. Used for
            idempotent submits.
        error_message:
          type: string
          description: >
            Populated when `status = failed`. The message is prefixed with a
            stable error code the UI / SDK can key on: `image_pull_failed`,
            `step_failed`, `boot_failed`, `snapshot_failed`, `start_cmd_failed`,
            `ready_cmd_failed`, or `build_failed` (fallback).
          example: 'step_failed: step 1/2 failed after 3s: exited with code 100'
        started_at:
          type: string
          format: date-time
        finalized_at:
          type: string
          format: date-time
        created_at:
          type: string
          format: date-time
    Error:
      type: object
      description: |
        Error envelope. `error.code` is a stable, machine-readable identifier
        (e.g. `bad_request`, `not_found`, `conflict`, `rate_limited`,
        `too_many_builds`, `too_many_templates`, `too_many_sandboxes`,
        `image_pull_failed`, `step_failed`, `snapshot_failed`,
        `start_cmd_failed`, `ready_cmd_failed`, `build_failed`).
        `error.message` is human-readable and may change between releases;
        clients should branch on `code`, not `message`.
      properties:
        error:
          type: object
          properties:
            code:
              type: string
            message:
              type: string
  responses:
    Unauthorized:
      description: Missing or invalid API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Conflict:
      description: Operation conflicts with the resource's current state
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    InternalError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: X-API-Key

````