Environments
An environment is where a session runs. You choose one rather than create one. The one environment is env_default, which runs each session in the cloud, wherever the platform places it. Nothing about it can be configured over this API. Remote sandbox support is on the roadmap.
Pass env_default as environment_id when you create a session.
Anthropic compatibility
Anthropic's SDKs also have environments.create, update, delete and archive. Code written for Anthropic's
API often creates an environment before its first session. This API handles those calls as follows:
POST /v1/environments(environments.create) creates nothing, so it has no page of its own here; the API reference the server serves lists it as Create an environment. It exists so that Anthropic SDK code runs unchanged. The key must havetasks:create. With noconfig, or acloudconfig with unrestricted networking and no packages, it returns200withenv_default. It ignoresname,descriptionandmetadata. Any otherconfigreturns400 invalid_request_error, as does any field this API doesn't accept, such asscope.- Updating, deleting or archiving an environment returns
404 not_found_error, because this API does not serve those paths.
The only environment is env_default. Remote sandbox support is on the roadmap.
Network access
Every environment reports networking.type as unrestricted, which is the only value the API accepts.
unrestricted means the session's sandbox can reach the public internet, unless your deployment restricts it (see
the note below). Model calls are separate. Context handles them, and the sandbox's network access doesn't govern them. Nothing you set
through the API changes network access.
Note: Self-hosted (KOTS) deployments can restrict sandbox outbound traffic to a list of allowed domains. It's a setting in the KOTS Admin Console, not in the API. Your administrator turns on Sandbox Egress Proxy (domain allowlist) and lists the domains in Sandbox Egress Proxy Allowlist, or turns off Sandbox Internet Access. With Sandbox Workload Identity on, the same choice is Sandbox Egress Posture, set to Open internet, Domain allowlist or Workspace only. The API's
networkinglabel doesn't reflect this setting, so environments reportunrestrictedeven when the install is tighter. To set it up, ask your Context contact.
A create with limited networking, packages or any other custom config returns 400:
Code
limited networking is on the Roadmap.
The environment object
| Field | Type | Description |
|---|---|---|
id | string | Always env_default. |
type | string | Always environment. |
name | string | Always default. |
description | string | A one-line description. |
config | object | An object whose type is cloud. It also holds networking, always unrestricted, and packages, always empty. |
created_at | string | When the environment was created, as an RFC 3339 timestamp. |
updated_at | string | When the environment last changed, as an RFC 3339 timestamp. |
Some fields always hold the same value: metadata is {} and archived_at is null. Treat the following values on env_default as placeholders, because they don't describe the real environment. Its description is a fixed string. Its config always reports networking: unrestricted and empty packages. If a self-hosted install restricts sandbox network access in the KOTS Admin Console, config doesn't show that yet.
Example
Code
List environments
Lists the environments a session can run in, which is the default cloud environment (env_default).
A session can run only in an environment from this list. The API has no call to create environments.
The key must have the tasks:read capability. For what each capability allows, see Keys.
Response
Returns 200 with the environments in data. Pass next_page as page to get the next page. next_page is null on the last page.
Errors
This endpoint can return these errors as well as the common errors.
| Status | error.type | Cause and fix |
|---|---|---|
| 400 | invalid_request_error | limit is outside 1 to 100. Send a value from 1 to 100. |
| 400 | invalid_request_error | page is not a next_page value from this API. Send the next_page value from the previous response, unchanged. |
query Parameters
limitThe maximum number of environments to return per page. Must be between 1 and 100.
The maximum number of environments to return per page. Must be between 1 and 100.
pageThe next_page value from the previous response. Leave it out to get the first page.
The next_page value from the previous response. Leave it out to get the first page.
include_archivedHas no effect, because environments are never archived.
Has no effect, because environments are never archived.
Headers
anthropic-workspace-idThe ID of a workspace in the key's organization that the key's owner works in. Agent and session requests run in that workspace; other requests only check it. The response echoes it. If the owner doesn't work there, the request returns 404. Without it, a new session runs in the agent's workspace or the owner's private workspace: see Where a session runs.
The ID of a workspace in the key's organization that the key's owner works in. Agent and session requests run in that workspace; other requests only check it. The response echoes it. If the owner doesn't work there, the request returns 404. Without it, a new session runs in the agent's workspace or the owner's private workspace: see Where a session runs.
List environments › Responses
Returns 200 with the environments in data. Pass next_page as page to get the next page. next_page is null on the last page.
next_pageGet an environment
Returns one environment, the default cloud environment (env_default).
To run a session in this environment, pass its id as environment_id when you create the session.
The key must have the tasks:read capability. For what each capability allows, see Keys.
Response
Returns 200 with the environment object. For every field, see Environments.
Errors
This endpoint can return these errors as well as the common errors.
| Status | error.type | Cause and fix |
|---|---|---|
| 404 | not_found_error | The ID is not env_default. Use env_default. |
path Parameters
environment_idThe ID of the environment to retrieve: env_default.
The ID of the environment to retrieve: env_default.
Headers
anthropic-workspace-idThe ID of a workspace in the key's organization that the key's owner works in. Agent and session requests run in that workspace; other requests only check it. The response echoes it. If the owner doesn't work there, the request returns 404. Without it, a new session runs in the agent's workspace or the owner's private workspace: see Where a session runs.
The ID of a workspace in the key's organization that the key's owner works in. Agent and session requests run in that workspace; other requests only check it. The response echoes it. If the owner doesn't work there, the request returns 404. Without it, a new session runs in the agent's workspace or the owner's private workspace: see Where a session runs.
Get an environment › Responses
Returns 200 with the environment object. For every field, see Environments.
Decision Table
| Variant | Matching Criteria |
|---|---|
| type = object · requires: id, archived_at, config +6 more | |
| type = object · requires: id, archived_at, config +7 more |
idarchived_atcreated_atdescriptionmetadatanametypeupdated_at