Environment object
Create, get, list, and update endpoints return this structure.
| フィールド | 型 | 説明 |
|---|
id | string | Environment ID(env_ プレフィックス付き) |
type | string | 固定値 "environment" |
name | string | Environment name, up to 255 characters. It must not be empty after trimming leading and trailing whitespace |
description | string | Environment の説明 |
config | Environment config | Normalized Environment configuration. Missing package-manager fields are added |
metadata | object | Environment metadata; defaults to {} when omitted |
archived_at | string | null | Archive time in RFC 3339 format; null while active |
created_at | string | Creation time in RFC 3339 format |
updated_at | string | Last update time in RFC 3339 format |
identity_id | string | null | Owning Forward identity. Returns the Identity ID for an Identity-owned resource, or null otherwise. See Identity ownership. |
icon_url | string | null | Icon URL associated by Forward |
binding_info | Binding info | Binding information, such as Template reference counts |
Identity の帰属
アカウント(または Workspace)には複数の Identity を作成できます。各 Identity は、そのアカウント(または Workspace)と連携する製品のエンドユーザーを表します。
Environment はアカウント(または Workspace)または特定の Identity に帰属できます。帰属によって、リソースを参照・操作できる範囲が決まります。
帰属の指定
| Caller | Owner | How to select |
|---|
| PAT | Account / Workspace | Omit identity_id (the default, unchanged behavior). |
| PAT | A specific Identity | Pass the query parameter identity_id=<identity_id>. |
| Admin SAT | Workspace | Resolved automatically; parameters cannot switch ownership. |
| Identity-bound SAT | The bound Identity | Resolved automatically; parameters cannot switch ownership. |
identity_id は Identity に属するリソースを操作する場合のみ使用する任意のパラメーターです。PAT では明示的に指定でき、省略時は管理者スコープになります。SAT では Identity スコープのトークンを発行し、空値を含め、このパラメーターを明示的に指定しないでください。指定すると HTTP 400 が返されます。
PAT で指定する Identity は、その PAT が表すアカウントまたは Workspace に属し、有効である必要があります。存在しない、無効化済み、削除済み、または呼び出し元に属さない場合は 404 が返されます。
帰属の分離
- アカウントまたは Workspace のスコープからは、Identity に属する Environment を参照できません。
- Identity は、アカウント(または Workspace)自体や同じアカウント内の他の Identity に属する Environment を参照できません。
- 有効な Identity スコープ(有効な
identity_id を指定した PAT または Identity SAT)では、別スコープのリソースに対する ID 指定の取得、更新、アーカイブ、削除はすべて 404 を返します。リソースが存在しない場合と、他の所有者に属する場合を区別しません。
identity_id を指定しない PAT と Admin SAT は従来どおり、Owner mismatch に対して 403 を返します。
対応するエンドポイント
Environment の作成、検索、一覧取得、取得、更新、アーカイブ、削除は identity_id クエリパラメーターに対応しています。
GET /api/v1/forward/resources/batch は、現時点では identity_id に対応していません。参照範囲のルールは従来どおりです。
Environment config
Environment runtime configuration. When omitted, it defaults to {"type":"cloud"}. When provided explicitly, it must not be null or an empty object.
self_hosted config
self_hosted Environment で使用できるのは type と任意の setup_script、startup_script のみです。packages またはサポートされていないフィールドを指定すると 400 invalid_request_error が返されます。self_hosted の startup_script は保存されてそのまま返されるだけで、実行するかどうかは外部 worker が決定します。
{"type": "self_hosted", "setup_script": "./initialize-worker.sh"}
cloud config response shape
A cloud config response includes every reserved package-manager array under packages; undeclared arrays are returned as []. For example:
{
"type": "cloud",
"packages": {
"type": "packages",
"apt": [],
"cargo": [],
"gem": [],
"go": [],
"npm": [],
"pip": []
}
}
Environment storage
storage.buckets[] は、サンドボックスの /mnt/buckets/<name> にマウントする自分の OSS bucket を宣言します。cloud config のみ対応し、最大 7 個です。詳細(認証情報、認可、権限ポリシー、サンドボックスの動作)は 自分の OSS Bucket をマウントする(Beta) を参照してください。
| フィールド | 型 | 必須 | 説明 |
|---|
name | string | はい | マウントディレクトリ名。同じ Environment 内で一意 |
provider | string | はい | 固定値 "aliyun-oss" |
region | string | はい | OSS region ID。例:cn-hangzhou |
bucket | string | はい | bucket 名 |
prefix | string | いいえ | このプレフィックスのみをマウント。省略時は bucket 全体 |
access | string | いいえ | read_only(デフォルト)または read_write |
accelerator_endpoint | string | いいえ | <label>.oss-data-acc.aliyuncs.com |
credential | object | はい | {"type":"ram_role","role_arn":"..."} または {"type":"access_key","access_key_id":"...","access_key_secret":"..."} |
credential は書き込み専用です。レスポンスには type のみが返され、access_key の場合はマスクされた access_key_id(例:LTAI****sKey)も返されます。更新時にこのフィールドを省略するか、マスク済みの値をそのまま返すと、保存済みの認証情報が保持されます。
{
"type": "cloud",
"storage": {
"buckets": [
{
"name": "datasets",
"provider": "aliyun-oss",
"region": "cn-hangzhou",
"bucket": "my-bucket",
"prefix": "team/data/",
"access": "read_only",
"credential": {"type": "ram_role", "role_arn": "acs:ram::1234567890123456:role/qoder-oss-mount"}
}
]
}
}
Environment packages
packages maps package-manager names to arrays of package specification strings. apt, npm, and pip currently install packages. cargo, gem, and go are reserved response fields and cannot currently install dependencies here.
| キー | 型 | 説明 | 例 |
|---|
type | string | Always "packages" in responses; do not supply it in requests | "packages" |
apt | array of string | Debian/Ubuntu package declarations, installed with apt-get install -y | ["git", "curl"] |
npm | array of string | Global Node.js package declarations, installed with npm install -g | ["pnpm@9"] |
pip | array of string | Python package declarations, installed with pip install | ["PyYAML==6.0.1"] |
cargo | array of string | Reserved response field; dependency installation through this field is not currently supported | [] |
gem | array of string | Reserved response field; dependency installation through this field is not currently supported | [] |
go | array of string | Reserved response field; dependency installation through this field is not currently supported | [] |
Every value must be an array of strings. Undeclared package-manager arrays are returned as [].
Environment setup script
setup_script is a shell script run during sandbox preparation after packages installation. Use it for initialization that cannot be expressed with packages, such as cloning code, writing configuration files, or warming caches.
| 制約 | 値 |
|---|
| 型 | string |
| 最大長 | 64 KB |
| インタープリタ | /bin/bash -lc |
| 実行タイミング | サンドボックス準備段階、packages インストール完了後 |
| タイムアウト | 10 分 |
| Nonzero exit | Fails preparation of the current sandbox |
| Repeated execution | Does not run again after succeeding in the same sandbox; runs again after the sandbox is reclaimed and rebuilt |
{
"config": {
"type": "cloud",
"setup_script": "set -euo pipefail\n[ -d /workspace/.git ] || git clone https://github.com/me/repo /workspace\ncd /workspace && pnpm install --frozen-lockfile"
}
}
Environment startup script
startup_script はサンドボックスが起動するたびに実行される shell スクリプトです。初回起動時は setup_script の後に実行され、一時停止から再開するたびに再実行されます。再開後はディスク上のファイルは残りますが、プロセスは残りません。インストール手順は setup_script に、データベースや dev server などのプロセスの起動は startup_script に記述します。
| 制約 | 値 |
|---|
| 型 | string |
| 最大長 | 64 KB |
| インタープリター | /bin/bash -lc。作業ディレクトリと環境変数は setup_script と同じ |
| 実行タイミング | サンドボックスの各起動後、最初のツールの実行前。初回起動時は setup_script の後 |
| タイムアウト | 5 分。タイムアウト時はスクリプトと、それが起動したバックグラウンドプロセスが停止される |
| 再実行 | 同じ起動内では最大 1 回(実行開始前に記録)。次回起動時に再実行 |
| 失敗 | Session に影響しない。起動ごとに失敗すると、error.type が environment_startup_failed_error の session.error が 1 件発生し、同じ起動内では再試行されない |
スクリプトは終了する必要があります。常駐プロセスはバックグラウンドで実行し、出力をファイルにリダイレクトします(例:nohup pnpm dev > /tmp/dev.log 2>&1 &)。再開時に以前のプロセスが動作している場合があるため(一部のランタイムは一時停止中もメモリを保持)、スクリプト側でサービスがすでに動作しているかを確認してください。
{
"config": {
"type": "cloud",
"packages": {"apt": ["redis-server"]},
"startup_script": "pgrep -x redis-server || redis-server --daemonize yes"
}
}
Custom Environment metadata key-value pairs. created_by is reserved by Forward and must not be supplied by callers (supplying it returns 400).
| 制約 | 値 |
|---|
| Caller-supplied limit | Typically 15 custom key-value pairs |
| Maximum key length | 64 characters |
| Value type | string |
| Maximum value length | 512 characters |
Binding info
Reference summary included by Forward in Environment responses.
| フィールド | 型 | 説明 |
|---|
agent_template_count | integer | Number of Templates currently bound to the Environment |
| フィールド | 型 | 説明 |
|---|
data | array of Environment objects | Records on the current page |
has_more | boolean | Whether another page is available |
next_page | string | null | Forward cursor for the next page (recommended). Equals the current page's last_id when has_more=true; otherwise null |
first_id | string | null | ID of the first record on the current page |
last_id | string | null | ID of the last record on the current page |
The request cursor parameters page, after_id, and before_id are mutually exclusive; providing more than one returns 400. Use page where possible; it has the same semantics as after_id.