Create a managed runtime environment with a container, dependencies, network policy, initial files, and skills.
Endpoint
POST /agents/environments
Creates a managed runtime environment. A successful call returns 201, which means the environment is registered and asynchronous preparation has started. Creating a session that references the environment before preparation completes can fail.
Request body
| Field | Required | Type | Description |
|---|---|---|---|
environment | Yes | object | Environment configuration, see below |
vault_ids | No | array<string> / null | Vaults to attach, up to 10 |
environment.type | Yes | string | Environment type, fixed as openai_hosted |
environment.environment_template_id | No | string | Environment template ID; the template must belong to the current workspace. Manage templates through Environment templates. |
environment.env | No | object | Environment variables; names must match [A-Za-z_][A-Za-z0-9_]*, cannot be PATH, and cannot start with a reserved prefix; values cannot contain NUL |
environment.packages | No | object | Packages grouped by npm, python, and system |
environment.network | No | object | Network policy, see below |
environment.files | No | array | Initial files; currently uses file_id to reference source files |
environment.desktop | No | object | Desktop settings; only enabled=false is accepted, and enabled=true returns 400 |
environment.setup_commands | No | array | Setup commands executed in order. Each item requires command and accepts an optional cwd; cwd defaults to /workspace |
environment.skills | No | array | Skills; currently uses skill_reference, up to 32 items |
environment.capability_directories | No | array | Capability discovery directories; must be under /workspace/ |
environment.network.access | No | string | Network access mode, enabled, disabled, or restricted |
environment.network.allowed_domains | No | array<string> | Allowed domains, required and non-empty when access=restricted; host names only, with no scheme, port, or wildcard |
environment.files[].type | Yes | string | File reference type, fixed as file_id |
environment.files[].path | Yes | string | Absolute path in the environment; must be under /workspace/ |
environment.files[].file_id | Yes | string | Source file ID returned by POST /agents/file |
environment.skills[].type | Yes | string | Skill reference type, fixed as skill_reference |
environment.skills[].skill_id | Yes | string | Skill resource ID |
environment.skills[].version | No | string | Skill version; if omitted, latest is resolved and frozen to a specific version |
plugins array is rejected. desktop.enabled=true is rejected. skill_id comes from the Skill API. Create or list skills first: Create a Skill or List Skills.
Create accepts an optional Idempotency-Key header. The same key and request body in the same workspace return the existing resource; the same key with a different body returns 409.
When mounting an unrestricted credential, network.access must be restricted, and allowed_domains must be non-empty and valid.
Example: "skills": [{"type": "skill_reference", "skill_id": "skill_xxx", "version": "1.0"}]
Request example
Response example
Response fields
| Field | Type | Description |
|---|---|---|
id | string | Environment ID |
object | string | Environment object type, fixed as agent.environment |
type | string | Environment type, fixed as openai_hosted |
status | string | Environment status: pending, ready, connected, disconnected, suspended, expired, or failed |
files | array | Safe metadata for installed files; file content is not returned. |
files[].id | string | Environment file ID |
files[].type | string | File reference type, fixed as file_id |
files[].path | string | File path in the environment |
files[].size_bytes | integer | File size in bytes |
files[].file_id | string | Original source file ID |
skills | array | Safe metadata for installed skills; package content is not returned. |
skills[].type | string | Skill reference type, fixed as skill_reference |
skills[].name | string | Skill name |
skills[].description | string | Skill description |
skills[].skill_id | string | Skill resource ID |
skills[].version | string | Frozen version |
plugins | array | Plugin list; currently [] for managed environments; plugin fields in historical records do not mean plugins can be created |
201 does not mean the environment is ready. Retrieve the status and confirm ready before use.
Error codes
| HTTP status | Error type / code | Solution |
|---|---|---|
400 | invalid_request_error / missing_required_parameter, param=environment | Provide environment in the request body |
400 | invalid_request_error / invalid_request_error | Fix type and the configuration as described for environment |
404 | not_found_error / not_found_error | Use a template or environment that exists and is accessible in the current workspace |
409 | conflict_error / conflict_error | Use the same request body with the same idempotency key |
503 | server_error / environment_unavailable or template_storage_unavailable | Retry later. If it keeps failing, submit a ticket with x-request-id |
{"error":{"type","code","message","param"}}. Gateway errors can use a different structure. Keep the HTTP status, x-request-id, and a redacted request body for troubleshooting.