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

# Create an environment

> Create a new cloud execution environment for hosting Agent sessions.

`POST /api/v1/cloud/environments`

Creates a new cloud execution environment for hosting Agent sessions.

## Headers

| Header          | Required | Description        |
| --------------- | -------- | ------------------ |
| `Authorization` | Yes      | `Bearer <PAT>`     |
| `Content-Type`  | Yes      | `application/json` |

## Request body

| Field         | Type                                                                            | Required | Description                       |
| ------------- | ------------------------------------------------------------------------------- | -------- | --------------------------------- |
| `name`        | string                                                                          | Yes      | Non-empty environment name        |
| `description` | string                                                                          | No       | Environment description           |
| `config`      | [Environment config](/cloud-agents/api/environments/schemas#environment-config) | Yes      | Environment configuration         |
| `metadata`    | [Metadata object](/cloud-agents/api/conventions/schemas#metadata-object)        | No       | Custom metadata. Defaults to `{}` |

## Example request

```bash theme={null}
curl -s -X POST 'https://api.qoder.com/api/v1/cloud/environments' \
  -H "Authorization: Bearer $QODER_PAT" \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "doc-test-env",
    "config": {
      "type": "cloud",
      "networking": {
        "type": "limited"
      },
      "packages": {
        "apt": ["curl"]
      }
    }
  }'
```

## Example request: with setup script

```bash theme={null}
curl -s -X POST 'https://api.qoder.com/api/v1/cloud/environments' \
  -H "Authorization: Bearer $QODER_PAT" \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "doc-test-env-with-setup",
    "config": {
      "type": "cloud",
      "networking": {"type": "unrestricted"},
      "packages": {
        "npm": ["pnpm@9"]
      },
      "setup_script": "set -euo pipefail\n[ -d /workspace/.git ] || git clone https://github.com/me/repo /workspace\ncd /workspace && pnpm install --frozen-lockfile"
    }
  }'
```

## Example response

**HTTP 200 OK**

```json theme={null}
{
  "id": "env_019e3bb39b6774d8878cd0b9d237574b",
  "type": "environment",
  "name": "doc-test-env",
  "description": "",
  "config": {
    "type": "cloud",
    "networking": {
      "type": "limited",
      "allowed_hosts": [],
      "allow_package_managers": false,
      "allow_mcp_servers": false
    },
    "packages": {
      "type": "packages",
      "apt": ["curl"],
      "npm": [],
      "pip": []
    }
  },
  "metadata": {},
  "archived_at": null,
  "created_at": "2026-05-18T15:28:07.017808Z",
  "updated_at": "2026-05-18T15:28:07.017808Z"
}
```

## Response fields

| Field         | Type                                                                            | Description                                          |
| ------------- | ------------------------------------------------------------------------------- | ---------------------------------------------------- |
| `id`          | string                                                                          | Environment unique identifier with the `env_` prefix |
| `type`        | string                                                                          | Always `"environment"`                               |
| `name`        | string                                                                          | Environment name                                     |
| `description` | string                                                                          | Environment description                              |
| `config`      | [Environment config](/cloud-agents/api/environments/schemas#environment-config) | Environment configuration                            |
| `metadata`    | [Metadata object](/cloud-agents/api/conventions/schemas#metadata-object)        | Custom metadata                                      |
| `archived_at` | string\|null                                                                    | Archive time (ISO 8601), `null` when not archived    |
| `created_at`  | string                                                                          | Creation time (ISO 8601)                             |
| `updated_at`  | string                                                                          | Last update time (ISO 8601)                          |

## Errors

| HTTP | Type                    | Trigger                                                 |
| ---- | ----------------------- | ------------------------------------------------------- |
| 400  | `invalid_request_error` | Missing required field `name`                           |
| 400  | `invalid_request_error` | Missing required field `config`                         |
| 400  | `invalid_request_error` | Invalid `config` or `metadata` value                    |
| 400  | `invalid_request_error` | `config.setup_script` is not a string, or exceeds 64 KB |
| 401  | `authentication_error`  | PAT invalid or expired                                  |
| 403  | `permission_error`      | Not authorized for this operation                       |

See [Errors](/cloud-agents/api/conventions/errors) for the full error envelope.

## Related

<CardGroup cols={2}>
  <Card title="Cloud environment setup" icon="server" href="/cloud-agents/environments">
    Choose the container, network, and dependencies your agent runs in.
  </Card>
</CardGroup>
