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

# Save and Test Warm Hook

> Saves the supplied script as the active warm hook for the environment and runs it in an isolated sandbox. For a source-backed personal environment, the test runs the Global hook, inherited source hook, and supplied personal hook in that order. The new version is activated only when the test passes. The endpoint takes 30–90 seconds to return because it spins up a real sandbox.



## OpenAPI

````yaml /openapi.json post /v1/environments/{environmentId}/warm-hooks/save-test
openapi: 3.1.0
info:
  title: Replica API
  version: 2.0.0
  description: >-
    The Replica API allows you to programmatically manage cloud workspaces for
    AI agents. Use this API to manage environments (the org-scoped primitive
    workspaces are created from — including variables, files, skills, MCPs, warm
    hooks, start hooks, and warm pools), create and manage replicas, send
    messages, manage chats, stream events, read connected repositories and
    repository sets, and configure automations.
servers:
  - url: https://api.tryreplicas.com
    description: Production API
security:
  - apiKey: []
tags:
  - name: Environments
    description: >-
      Manage environments — the primitive that workspaces are created from.
      Variables, files, skills, MCPs, warm-hooks, and warm-pools are all scoped
      to an environment. Every organization has a singleton Global environment
      whose values apply to every workspace. Personal environments are scoped to
      the authenticated user and can be standalone or source-backed by a team
      environment.
  - name: Repository
    description: >-
      Read repositories and repository sets connected to your organization.
      Repositories are the underlying GitHub-connection layer; bind them to an
      environment to use them in workspaces.
  - name: Replica
    description: >-
      Manage replicas (workspaces) for AI agents. `/v1/replica` endpoints accept
      API keys and workspace engine-secret authentication; user-session JWTs are
      not accepted.
  - name: Terminal
    description: Manage interactive terminal sessions in active workspaces
  - name: Preview
    description: Manage public preview URLs for workspace ports
  - name: Profile
    description: Read and update the authenticated user's profile
  - name: Credentials
    description: >-
      Manage coding-agent credentials for an organization or the authenticated
      user
  - name: Google Search Console
    description: >-
      Read Search Console properties, performance, sitemaps, and URL inspection
      results through a connected Google account
  - name: Slack
    description: Connect Slack identities and route threads to Replicas workspaces
  - name: Linear
    description: Connect Linear identities to Replicas accounts
  - name: Automation
    description: >-
      Create and manage automations that trigger replicas on a schedule or in
      response to events
  - name: Downloads
    description: Download Replicas applications
  - name: Media
    description: >-
      Read workspace media and obtain short-lived download or inline preview
      URLs
  - name: Analytics
    description: >-
      Read aggregated activity and usage metrics for your organization: compute
      minutes, workspaces created by source, and pull request throughput over a
      time range.
  - name: Presence
    description: >-
      Read and report ephemeral member presence: who is online, where they are
      (environment or workspace), and whether they are typing. Presence is
      backed by short-lived keys rather than the database and broadcast to other
      members over the events stream.
paths:
  /v1/environments/{environmentId}/warm-hooks/save-test:
    post:
      tags:
        - Environments
      summary: Save and Test Warm Hook
      description: >-
        Saves the supplied script as the active warm hook for the environment
        and runs it in an isolated sandbox. For a source-backed personal
        environment, the test runs the Global hook, inherited source hook, and
        supplied personal hook in that order. The new version is activated only
        when the test passes. The endpoint takes 30–90 seconds to return because
        it spins up a real sandbox.
      operationId: saveAndTestEnvironmentWarmHook
      parameters:
        - name: environmentId
          in: path
          required: true
          description: Environment UUID, or the literal string `global`.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SaveAndTestWarmHookRequest'
      responses:
        '201':
          description: Warm hook saved (test result included in body)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SaveAndTestWarmHookResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  schemas:
    SaveAndTestWarmHookRequest:
      type: object
      properties:
        content:
          type: string
          description: Shell script to save and execute
      required:
        - content
    SaveAndTestWarmHookResponse:
      type: object
      properties:
        warm_hook:
          $ref: '#/components/schemas/WarmHookRecord'
        test:
          $ref: '#/components/schemas/WarmHookTestResult'
      required:
        - warm_hook
        - test
    WarmHookRecord:
      type: object
      description: >-
        A warm hook — the shell script that runs while pre-warming workspaces
        for an environment.
      properties:
        id:
          type: string
          format: uuid
        organization_id:
          type: string
          format: uuid
        environment_id:
          type: string
          format: uuid
        version:
          type: integer
          description: Monotonic version (newer scripts have higher versions)
        content:
          type: string
          description: Shell script content
        is_active:
          type: boolean
          description: Whether this version is the active one for the environment
        created_at:
          type: string
          format: date-time
      required:
        - id
        - organization_id
        - environment_id
        - version
        - content
        - is_active
        - created_at
    WarmHookTestResult:
      type: object
      description: Result of running a warm hook script in an isolated sandbox.
      properties:
        exit_code:
          type: integer
          description: Process exit code (0 = success)
        output:
          type: string
          description: Captured stdout + stderr
        timed_out:
          type: boolean
          description: Whether execution was killed for taking too long
      required:
        - exit_code
        - output
        - timed_out
    Error:
      type: object
      properties:
        error:
          type: string
          description: Error message
        details:
          type:
            - string
            - 'null'
          description: Additional error details
      required:
        - error
  responses:
    BadRequest:
      description: Bad request - Missing or invalid parameters
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Unauthorized - Invalid or missing API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: >-
        API key authentication. Obtain your API key from the Replicas dashboard
        under Organization → Settings → API Keys. User-session JWTs are not
        accepted by `/v1/replica` endpoints.

````