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

# Create an environment

> Leases an environment from a template and queues it for a hot node. Poll `GET /v1/environments/{id}` until `state` is `ready`. When a sandbox is given, the answer includes the sandbox's new envd configuration.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/environments
openapi: 3.1.0
info:
  title: envlink API
  version: 1.0.0
  description: >-
    Lease build environments, wire them to your sandbox, and keep snapshots and
    artifacts.
servers:
  - url: https://envlink-api.projectinwork.com
security:
  - bearerAuth: []
tags:
  - name: Environments
  - name: Templates
  - name: Sandboxes
  - name: Snapshots
  - name: Artifacts
  - name: Projects
  - name: Tokens
  - name: Usage
  - name: Account
paths:
  /v1/environments:
    post:
      tags:
        - Environments
      summary: Create an environment
      description: >-
        Leases an environment from a template and queues it for a hot node. Poll
        `GET /v1/environments/{id}` until `state` is `ready`. When a sandbox is
        given, the answer includes the sandbox's new envd configuration.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateEnvironment'
      responses:
        '202':
          description: Queued
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnvironmentAnswer'
        '404':
          description: No such template or sandbox
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: A bad label, share, pattern, project or snapshot key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Over the organization's quota
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: The queue didn't take it; the environment is marked failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    CreateEnvironment:
      type: object
      properties:
        template:
          type: string
          examples:
            - linux-build
        sandbox:
          type: string
          description: >-
            The sandbox to wire it to; needed for shares and for services on
            localhost.
        shares:
          type: object
          additionalProperties:
            type: string
          description: >-
            A template in share → a folder on the sandbox, relative to its
            folder.
          examples:
            - src: .
        labels:
          type: object
          additionalProperties:
            type: string
        idle:
          type: string
          examples:
            - 30m
        hard:
          type: string
          examples:
            - 6h
          description: At most 24h.
        project:
          type: string
          description: Whose key seals its files; default.
          examples:
            - github.com/acme/app
        snapshot:
          type: string
          description: Save its synced files under this key when it ends.
        restore:
          type: array
          items:
            type: string
          description: >-
            Snapshot keys to start from, in order: exact match, then the newest
            prefix match. Defaults to snapshot.
        include:
          type: array
          items:
            type: string
          description: >-
            Paths or globs to send even if .gitignore or the defaults leave them
            out.
        noIgnore:
          type: boolean
          description: Don't apply .gitignore files or the default ignores.
        files:
          type: object
          additionalProperties:
            type: string
          description: 'Extra files: destination in the share → source on the sandbox.'
      required:
        - template
    EnvironmentAnswer:
      type: object
      properties:
        environment:
          $ref: '#/components/schemas/Environment'
        sandboxConfig:
          type: object
          description: The sandbox's new envd configuration, when one is wired.
    Error:
      type: object
      properties:
        error:
          type: string
          description: What went wrong, for people.
        code:
          type: string
          description: >-
            A machine-readable code, when there is one: quota, no_template,
            not_found, …
      required:
        - error
    Environment:
      type: object
      properties:
        id:
          type: string
          examples:
            - env_3iynbifi4k6xgfhn
        name:
          type: string
          examples:
            - linux-build-3f2a
        template:
          type: string
          examples:
            - linux-build
        state:
          type: string
          enum:
            - pending
            - starting
            - ready
            - stopping
            - stopped
            - failed
        node:
          type: string
          description: The node it runs on.
        sandbox:
          type: string
          description: The sandbox it's wired to.
        pool:
          type: string
          examples:
            - linux-arm64
        labels:
          type: object
          additionalProperties:
            type: string
        project:
          type: string
          description: Whose key seals its files.
          examples:
            - github.com/acme/app
        readyMs:
          type: integer
          description: From request to ready.
        error:
          type: string
        createdBy:
          type: string
        created:
          type: string
          format: date-time
        ready:
          type: string
          format: date-time
        stopped:
          type: string
          format: date-time
        expires:
          type: string
          format: date-time
        idleUntil:
          type: string
          format: date-time
        idle:
          type: string
          examples:
            - 1h0m0s
        hard:
          type: string
          examples:
            - 6h0m0s
        exports:
          type: array
          items:
            $ref: '#/components/schemas/Export'
        shares:
          type: array
          items:
            $ref: '#/components/schemas/Share'
        snapshot:
          type: string
          description: The key its files are saved under when it ends.
        restored:
          $ref: '#/components/schemas/Restored'
    Export:
      type: object
      properties:
        service:
          type: string
          examples:
            - postgres
        listen:
          type: string
          description: Where the sandbox reaches it.
          examples:
            - 127.0.0.1:5432
        target:
          type: string
          description: The service's address inside the environment.
          examples:
            - 127.0.0.1:5432
    Share:
      type: object
      properties:
        name:
          type: string
          examples:
            - src
        direction:
          type: string
          enum:
            - in
            - out
        envPath:
          type: string
          examples:
            - /work
        localPath:
          type: string
          description: On the sandbox, relative to its folder.
          examples:
            - .
        files:
          type: array
          items:
            type: string
          description: Extra files' destinations.
    Restored:
      type: object
      properties:
        key:
          type: string
        root:
          type: string
        files:
          type: integer
        created:
          type: string
          format: date-time
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: A CLI token or an organization API key.

````

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