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

# Create an environment

> Provisions an environment under the identifier the caller names, on the one official image, and runs the caller's setup script inside it once. **Idempotent on that identifier** when the existing machine's setup state is recorded: such an id is answered 200 with the environment that exists, not 409 and not a second container — a client that lost the response to its first call may repeat it without paying twice. A setup-carrying create that meets a machine whose setup state was never recorded is refused rather than adopted: nobody can say whether that machine's toolchain exists. A setup script that fails or runs past the host's bound leaves the environment `unusable` carrying its own output as the cause, rather than a healthy-looking environment missing a toolchain.



## OpenAPI

````yaml /pt/openapi/v3-current/narya.yaml post /v1/environments
openapi: 3.1.0
info:
  title: Narya Host API
  version: 1.0.0
  description: >-
    The contract between the Narya host and every client. On your own machine,
    one long-lived host serves this API over a Unix socket in your Narya home.
    The terminal client and the one-shot command that Lerian ships drive this
    API, and a client you write drives the same one.


    Requests authenticate with a bearer token issued by the identity provider
    the host is configured with. On your own machine, the host also accepts a
    request with no token from your own operating system user. Once signed-in
    work has claimed the home for an organization, it does so only while this
    machine is signed in to that organization. Such a request gets 401 with
    NRY-0011 on work that reaches your organization beyond the machine. An
    operation that declares another security scheme also accepts that
    credential. Any other request without a valid credential gets 401 with
    NRY-0011. A caller whose role lacks the permission an operation needs gets
    403 with NRY-0028.


    Submitting a message returns 202 with a turn id. Everything the turn
    produces streams over GET /v1/events as server-sent events with a typed
    envelope, and a stream resumes from a Last-Event-ID header.


    One error envelope: code, title and message. Codes are NRY- followed by four
    digits. Cursors are opaque.
servers: []
security:
  - bearerAuth: []
tags:
  - name: host
    description: The host process itself — version, uptime, mode, store.
  - name: sessions
    description: Durable conversation containers. Archive, never destroy.
  - name: messages
    description: Submitting work into a session and interrupting it.
  - name: events
    description: The server-sent event stream every client consumes.
  - name: lanes
    description: Parallel tracks inside a session — main, subagent, side.
  - name: agents
    description: Named recipes — instructions, tools, model, policy. Read-only in v1.
  - name: ladder
    description: >-
      What a person can type: the skills and command files in force for one
      repository, and expanding one into text. Five origins merged, nearest
      winning a name, the repository's own rungs gated on trust.
  - name: permissions
    description: Pending permission asks, decisions, and the decision audit.
  - name: intercom
    description: Sessions on one machine finding and messaging each other.
  - name: packages
    description: The one thing a user installs — resources, Go code, or both.
  - name: extensions
    description: >-
      Host-side extensions and the operations each exposes over the wire. This
      is the generic lane a host extension uses to serve its own client half (a
      TUI component, a web panel) or any API-only consumer, without adding
      routes to this contract.
  - name: workflows
    description: Deterministic multi-agent orchestration runs.
  - name: providers
    description: Model suppliers, their auth state, and the model catalogue.
  - name: monitors
    description: >-
      Long-running watchers a session keeps beside its conversation — a test
      runner in watch mode, a build, a log being followed. Started by the model
      or by the person, always listed, always killable.
  - name: records
    description: The queryable local record of everything that happened.
  - name: environments
    description: >-
      Where a session's code lives and its commands run — this machine, or a
      container narya operates. A session that names none runs here.
  - name: schedules
    description: >-
      Work the host's own clock starts with nobody present — a repository, a
      prompt, a rule and what one fire may spend. Cancel, never destroy.
  - name: sharing
    description: >-
      Publishing a session from a developer's own home to the organisation's,
      and what is held back before a byte leaves the machine.
  - name: refinements
    description: >-
      What this owner has taught narya and allowed it to keep — distilled facts,
      and the skills, agents and commands the model wrote for itself. Propose,
      read, consent, roll back. Nothing here fires until a person answers.
  - name: platform
    description: >-
      Calls Lerian's control plane made to a home it hosts, as this home
      recorded them.
paths:
  /v1/environments:
    post:
      tags:
        - environments
      summary: Create an environment
      description: >-
        Provisions an environment under the identifier the caller names, on the
        one official image, and runs the caller's setup script inside it once.
        **Idempotent on that identifier** when the existing machine's setup
        state is recorded: such an id is answered 200 with the environment that
        exists, not 409 and not a second container — a client that lost the
        response to its first call may repeat it without paying twice. A
        setup-carrying create that meets a machine whose setup state was never
        recorded is refused rather than adopted: nobody can say whether that
        machine's toolchain exists. A setup script that fails or runs past the
        host's bound leaves the environment `unusable` carrying its own output
        as the cause, rather than a healthy-looking environment missing a
        toolchain.
      operationId: createEnvironment
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EnvironmentCreate'
      responses:
        '200':
          description: >-
            The environment that already existed under this identifier. Nothing
            was provisioned and no setup script ran.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Environment'
        '201':
          description: The environment.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Environment'
        '400':
          $ref: '#/components/responses/BadRequest'
        '413':
          $ref: '#/components/responses/RequestBodyTooLarge'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  schemas:
    EnvironmentCreate:
      type: object
      description: >-
        Request to provision an environment. No image is named: there is one
        official image, and the customer's own tooling arrives as the script
        below, on top of it.
      required:
        - id
      properties:
        id:
          $ref: '#/components/schemas/EnvironmentId'
        setupScript:
          type: string
          maxLength: 65536
          description: >-
            A script run once inside the new environment, after the image is up
            and before any session uses it — where a customer's own toolchain
            arrives. It runs bounded in time; a non-zero exit or a run past the
            bound leaves the environment `unusable` with this script's own
            output as the cause, rather than an environment that looks healthy
            and cannot build anything.
        repository:
          type: string
          maxLength: 200
          pattern: ^[A-Za-z0-9][A-Za-z0-9._-]*/[A-Za-z0-9][A-Za-z0-9._-]*$
          description: >-
            A repository this organisation selected when it installed Narya's
            GitHub App, as `owner/name`. The host clones it into the
            environment's workspace BEFORE the environment's own machine exists,
            so the machine holds the code and never the credential that fetched
            it: the clone runs in a throwaway Lerian container over the same
            workspace, as the same unprivileged user the environment runs as,
            and the short-lived installation token lives only for that one
            command. The clone happens before the setup script, so a script can
            build what was just cloned.

            A repository that is not in the installed set, an organisation that
            has connected no installation, and an installation its owner
            uninstalled or suspended on GitHub, are refused before any machine
            is made, and the refusal names the connect gesture. A clone that
            fails leaves the environment `unusable` with the cause as its setup
            output, exactly as a failed setup script does. Omit it for an
            environment that starts empty.
      examples:
        - id: build-box
          repository: acme/widgets
          setupScript: |
            set -eux
            apt-get update && apt-get install -y --no-install-recommends make
    Environment:
      type: object
      description: >-
        A place a session's code lives and its commands run. The host's own
        machine is not one of these — it is what a session gets by naming none.
      required:
        - id
        - state
        - image
        - createdAt
      properties:
        id:
          $ref: '#/components/schemas/EnvironmentId'
        state:
          $ref: '#/components/schemas/EnvironmentState'
        image:
          type: string
          maxLength: 512
          description: >-
            The immutable digest of the image this environment actually runs,
            pinned when it was created and never floated afterwards.
            Reconnecting after a host restart, and replacing an environment that
            was lost, both ask for this digest again, so an environment that
            worked yesterday is the same environment today. There is one
            official image, which is why nothing supplies this on creation.
        setup:
          $ref: '#/components/schemas/EnvironmentSetup'
          description: What the setup script did, absent when none was supplied.
        createdAt:
          type: string
          format: date-time
      examples:
        - id: build-box
          state: ready
          image: >-
            ghcr.io/lerianstudio/narya-sandbox@sha256:3f7a1c2b9d4e5f60718293a4b5c6d7e8f9012345678901234567890abcdefabcd
          setup:
            outcome: succeeded
            output: |
              + go version
              go version go1.26.0 linux/amd64
          createdAt: '2026-08-29T09:12:00.000Z'
    EnvironmentId:
      type: string
      minLength: 1
      maxLength: 64
      pattern: ^[A-Za-z0-9][A-Za-z0-9._-]*$
      description: >-
        An environment's identifier, chosen by whoever creates it and unique on
        this host. It travels as one path segment, so its shape is bounded to
        what a path segment carries unchanged, exactly as a monitor's name is: a
        "/" would address no route and a "?" or "#" would end the segment early
        and address something else. One beginning `conversation-` is a hosted
        home's own, and a create naming it is 422.
    EnvironmentState:
      type: string
      enum:
        - ready
        - degraded
        - gone
        - unusable
      x-enum-varnames:
        - EnvironmentStateReady
        - EnvironmentStateDegraded
        - EnvironmentStateGone
        - EnvironmentStateUnusable
      description: >-
        Whether an environment is answering, and — when it is not — whether
        waiting is the right move. The distinction is the whole point: a session
        waiting on an unreachable environment looks identical to a slow one
        otherwise, and what the person does next depends entirely on which it
        is. ready — answering; work proceeds. degraded — not answering right now
        and expected back: a restart or a dropped connection, which the host
        retries so the next call may simply succeed, or a container stopped
        outside narya, which the next turn starts. gone — destroyed, its name
        taken by another environment since, or the runtime no longer has it. A
        hosted home also removes a container nothing has used for 15 minutes and
        keeps its disks, the workspace and its restore points, and so does a
        person's own home for a conversation's own `conversation-<sessionId>`;
        it reads gone until a turn needs it. A session bound to it is then given
        a new container on its next turn, over the disks the old one left when
        those are still there, and is told which; on a person's own home a named
        environment that is gone needs a new one. unusable — its setup did not
        succeed; `setup` says what happened.
    EnvironmentSetup:
      type: object
      description: >-
        The outcome of the one setup script an environment runs at creation. It
        exists so a script that failed is visible now instead of discoverable at
        the first build the model cannot explain.
      required:
        - outcome
      properties:
        outcome:
          type: string
          enum:
            - succeeded
            - failed
            - timedOut
          x-enum-varnames:
            - EnvironmentSetupOutcomeSucceeded
            - EnvironmentSetupOutcomeFailed
            - EnvironmentSetupOutcomeTimedOut
          description: >-
            succeeded — the script exited zero and the environment is usable.
            failed — it exited non-zero; the environment is `unusable` and
            `output` is the cause. timedOut — it ran past the host's bound and
            was killed, which is reported as itself rather than as a hang,
            because a script waiting on a prompt and a script doing slow work
            are indistinguishable from the outside and only one of them is worth
            waiting for.
        output:
          type: string
          maxLength: 65536
          description: >-
            What the script wrote, both streams interleaved as they arrived,
            trimmed to this bound, keeping its end: the last thing a failing
            script said is the part that names the failure.
    Error:
      type: object
      description: >-
        The single error envelope every operation returns. Codes are NRY-
        followed by four digits and are catalogued in the top-level
        x-error-catalog extension.
      required:
        - code
        - title
        - message
      properties:
        code:
          type: string
          pattern: ^NRY-[0-9]{4}$
          description: Machine-readable error code from the NRY catalogue.
        title:
          type: string
          maxLength: 256
          description: Short human-readable summary of the error class.
        message:
          type: string
          maxLength: 4096
          description: Specific, actionable description of what went wrong.
        fields:
          type: object
          description: Per-field validation problems.
          additionalProperties:
            type: string
      examples:
        - code: NRY-0002
          title: Session not found
          message: >-
            No session with id 6b9f6d2e-1c3a-4f5b-9d7e-2a8c4e6f0b1d exists on
            this host.
  responses:
    BadRequest:
      description: Malformed request — invalid parameter, cursor, or JSON body.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    RequestBodyTooLarge:
      description: >-
        The request body weighs more than this operation accepts (NRY-0024). The
        host holds one ceiling per operation and refuses at the door, in front
        of every handler: a body whose declared Content-Length is past the
        ceiling is refused before a byte of it is read, and a body that declares
        no length is read only as far as the ceiling and refused there. Nothing
        was read past that point and nothing was written.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    UnprocessableEntity:
      description: The request was well-formed but failed validation.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    InternalServerError:
      description: The host failed — including a store that refuses writes (NRY-0012).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        Enforced on every transport, with no exempt operation. A person's
        request must carry a JWT issued by the configured identity provider,
        which the host verifies itself against that issuer's key set: signature,
        issuer, expiry, and the person and organisation it names. Requests
        without a valid one receive 401 NRY-0011 — except a request with no
        token on a laptop's socket from the OS user the kernel names as the
        host's own, which is that machine's user.

````

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