---
title: "Create Environment"
method: POST
path: "/agents/{namespace_slug}/{agent_name}/environments"
tags: ["Environments"]
---

# Create Environment

`POST /agents/{namespace_slug}/{agent_name}/environments`

Create a new environment for an agent.

    Environments define deployment targets with branch matching rules.
    The is_prod flag cannot be set via API - production environment is protected.

    **Branch Rules:**
    - Exact match: ["main"] or ["develop"]
    - Wildcard: ["feature/*"] matches feature/foo, feature/bar
    - Catch-all: ["*"] matches any branch

## Path parameters

- `namespace_slug` string, required
- `agent_name` string, required

## Request body

- CreateEnvRequest — Request to create a new environment.
  - `branch_rules` string[], required — Branch patterns for matching (e.g., ['feature/*'], ['develop'])
  - `name` string, required — Environment name (lowercase alphanumeric and hyphens only)

## Response `201`

Successful Response

- EnvResponse — Full environment details.
  - `agent_id` string, required — Parent agent ID
  - `branch_rules` string[], required — Branch patterns for matching (e.g., ['main'], ['feature/*'])
  - `created_at` string, date-time, nullable — Creation timestamp
  - `id` string, required — Unique identifier
  - `is_prod` boolean, required — Whether this is the production environment (protected)
  - `name` string, required — Environment name (e.g., 'production', 'staging')
  - `updated_at` string, date-time, nullable — Last update timestamp

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/terminaluse/apis/sb0-api.md) · [All operations](https://skmtc.net/terminaluse/apis/sb0-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/terminaluse/sb0-api/versions/f24a474dc415/schema)
