---
title: "Create an environment [write]"
method: POST
path: "/environments"
tags: ["environments"]
---

# Create an environment \[write\]

`POST /environments`

## Request

- Base URL: `https://api.agentsky.dev/v1`
- URL: `https://api.agentsky.dev/v1/environments`
- Auth: HTTP bearer

The image build starts immediately; the environment is usable as `environment_id` on POST /sessions as soon as it exists, and a session created against a still-building environment waits for the build. Supplying `extends` (an `env_…` id in the same workspace) composes packages, tools.disabled and networking from the parent at write time and records the lineage. `extends` is immutable after create; chain depth is capped at 16.

## Request body

- CreateEnvironment
  - `name` string, required
  - `config` object
    - `type` 'cloud'
    - `packages` object
      - `apt` string[]
      - `pip` string[]
      - `npm` string[]
    - `networking` union
      - object
        - `type` 'unrestricted', required
      - object
        - `type` 'limited', required
        - `allowed_hosts` string[]
        - `allow_mcp_servers` boolean
        - `allow_package_managers` boolean
  - `extends` string

## Response `201`

Created

- object
  - `environment` Environment, required
    - `id` string, required: env_…
    - `name` string, required
    - `config` object, required: `packages` are installed into the image at build time — an environment is built when it is created and rebuilt when its config changes, so a session starting from it pays no install cost. `networking` is the egress policy its sessions run under; `limited` needs `allow_package_managers` when packages are declared, or the install could never succeed.
      - `type` 'cloud'
      - `packages` object
        - `apt` string[]
        - `pip` string[]
        - `npm` string[]
      - `networking` union
        - object
          - `type` 'unrestricted', required
        - object
          - `type` 'limited', required
          - `allowed_hosts` string[]
          - `allow_mcp_servers` boolean
          - `allow_package_managers` boolean
    - `is_default` boolean, required: Whether a new session that names no environment uses this one. At most one per workspace; setting it on one clears it on the others.
    - `extends` string, nullable, required: The env_… id of the parent environment this one extends, or null. Immutable after create. Child packages, tools.disabled and networking compose on the parent's at write time.
    - `created_at` string, date-time, required
    - `updated_at` string, date-time, required

## Other responses

- `default`: Error — { error: { code, message } }

## Changes

- **2026-11-02** `e5e8f0229a99`: 3 info
  - added the new optional request property `extends`
  - added the optional property `error/request_id` to the response with the `default` status
  - added the required property `environment/extends` to the response with the `201` status

[Operation history](https://skmtc.dev/agentsky/apis/agentsky-developer-api/changes/environments/post.md)

---

[API](https://skmtc.dev/agentsky/apis/agentsky-developer-api.md) - [All operations](https://skmtc.dev/agentsky/apis/agentsky-developer-api/llms.txt) - [OpenAPI document](https://skmtc.dev/agentsky/apis/agentsky-developer-api/revisions/0d435187cd55?raw)
