> ## 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.

# Environment の作成

> 新しいクラウド実行 Environment を作成し、Agent セッションをホスティングします。

`POST /api/v1/cloud/environments`

Agent セッションをホストするための新しいクラウド実行環境を作成します。

## リクエストヘッダー

| ヘッダー            | 必須 | 説明                 |
| --------------- | -- | ------------------ |
| `Authorization` | はい | `Bearer <PAT>`     |
| `Content-Type`  | はい | `application/json` |

## リクエストボディ

| フィールド         | 型                                                                                  | 必須  | 説明                  |
| ------------- | ---------------------------------------------------------------------------------- | --- | ------------------- |
| `name`        | string                                                                             | はい  | 空でない Environment 名  |
| `description` | string                                                                             | いいえ | Environment の説明     |
| `config`      | [Environment config](/ja/cloud-agents/api/environments/schemas#environment-config) | はい  | Environment 設定      |
| `metadata`    | [Metadata オブジェクト](/ja/cloud-agents/api/conventions/schemas#metadata-オブジェクト)        | いいえ | カスタムメタデータ。省略時は `{}` |

## リクエスト例

```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"]
      }
    }
  }'
```

## リクエスト例：セットアップスクリプト付き

```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"
    }
  }'
```

## レスポンス例

**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"
}
```

## レスポンスフィールド

| フィールド         | 型                                                                                  | 説明                                   |
| ------------- | ---------------------------------------------------------------------------------- | ------------------------------------ |
| `id`          | string                                                                             | Environment の一意識別子（`env_` プレフィックス付き） |
| `type`        | string                                                                             | リソースタイプ、固定値 `"environment"`          |
| `name`        | string                                                                             | Environment 名                        |
| `description` | string                                                                             | Environment の説明                      |
| `config`      | [Environment config](/ja/cloud-agents/api/environments/schemas#environment-config) | Environment 設定                       |
| `metadata`    | [Metadata オブジェクト](/ja/cloud-agents/api/conventions/schemas#metadata-オブジェクト)        | カスタムメタデータ                            |
| `archived_at` | string\|null                                                                       | アーカイブ時刻（ISO 8601）、未アーカイブ時は `null`    |
| `created_at`  | string                                                                             | 作成時刻（ISO 8601）                       |
| `updated_at`  | string                                                                             | 最終更新時刻（ISO 8601）                     |

## エラーコード

| HTTP | type                    | 説明                                             |
| ---- | ----------------------- | ---------------------------------------------- |
| 400  | `invalid_request_error` | 必須フィールド `name` が未指定                            |
| 400  | `invalid_request_error` | 必須フィールド `config` が未指定                          |
| 400  | `invalid_request_error` | `config` または `metadata` の値が不正                  |
| 400  | `invalid_request_error` | `config.setup_script` が文字列でない、または 64 KB を超えている |
| 401  | `authentication_error`  | 認証失敗、PAT が無効または期限切れ                            |
| 403  | `permission_error`      | この操作を実行する権限がない                                 |

## 関連

<CardGroup cols={2}>
  <Card title="クラウド環境" icon="server" href="/ja/cloud-agents/environments">
    Agent が実行されるコンテナ、ネットワーク、依存関係を選択する。
  </Card>
</CardGroup>
