environment_id when it is created. This page covers cloud environments; to run a worker on your own infrastructure, see Self-Hosted Environments.
Each session runs in its own isolated sandbox instance. Sessions bound to the same execution environment do not share workspace state.
Create an execution environment
Send aPOST /v1/environments request to create an execution environment. The following example preinstalls packages with pip and apt, restricts outbound network access, and creates a working directory after package installation completes:
id and current build_status. Save the id so you can pass it as environment_id when creating a session.
Configure an execution environment
For cloud environments, setconfig.type to "cloud". The packages, networking, and setup_script fields are all optional—include or omit them based on your workload.
Preinstalled packages
Declare dependencies to preinstall underpackages, grouped by package manager. The platform installs these packages before the agent starts, and the resulting image is reused across sessions bound to the same execution environment.
Each entry uses the native version syntax of its package manager. Specify a version to pin it, or omit the version to install the latest release. You can configure at most 128 entries per package manager.
Network access
Thenetworking field controls outbound network access from processes inside the sandbox. It does not affect network access performed by platform-managed tools. When networking is omitted, the environment uses unrestricted mode.
In
limited mode:
- Entries in
allowed_hostsfall into two categories. Domain entries support exact hostnames and*.example.comwildcards (matching subdomains at any depth, excluding the apex domain itself) and may include a port (such asapi.example.com:8443). If you omit the port, only ports 80 and 443 are allowed. IP address and CIDR block entries (such as1.2.3.4or10.0.0.0/8) allow direct TCP connections on all ports and must not include a port. Entries must not include a URL scheme (such ashttps://) or a path. You can configure at most 128 entries; invalid entries are rejected with HTTP400when creating or updating the execution environment. allow_mcp_serverscontrols whether to additionally allow access to MCP server endpoints configured on the agent. Defaults tofalse.allow_package_managerscontrols whether to additionally allow access to public package registries such as PyPI and npm. Defaults tofalse.
proxy to route outbound traffic for specified hosts through your own proxy server. proxy.hosts lists the hosts to route through the proxy; in limited mode, hosts listed in proxy.hosts can be accessed through the proxy directly without also adding them to allowed_hosts:
Omit
auth if your proxy does not require authentication. In production environments, the proxy URL must use HTTPS regardless of authentication method; client_cert requires HTTPS in all environments.
The optional proxy.ca field accepts a PEM-encoded CA certificate bundle. Proxy credentials are referenced by vault_id and credential_id, so plaintext secrets are never stored in the execution environment configuration. The referenced credential must be an active environment_variable credential in the vault; other credential types are rejected with HTTP 400. See Vaults to create and manage credentials.
Setup script
Usesetup_script for one-time preparation tasks such as creating directories or generating configuration files.
Use in a session
Passenvironment_id when creating a session to bind it to an execution environment. You cannot change a session’s execution environment after binding. For complete request examples, see Create a Session.
To be used for new sessions, an execution environment must be visible to the caller, must not be archived, and must have at least one ready version.
Wait for the environment build to finish
After you create an environment or replace its configuration, the platform builds a new version asynchronously. If you want new sessions to use the configuration you just submitted, poll the environment by ID untilbuild_status becomes ready:
build_status indicates the build status of the latest configuration version:
If the latest version is still
building or has failed, new sessions fall back to the most recent ready version. Session creation fails only if the execution environment has no ready version at all.
A session pins the latest ready version of the execution environment at creation time and continues using that version for its entire lifetime. Subsequent updates to the execution environment do not affect existing sessions.
Update an execution environment
Send aPATCH /v1/environments/{id} request to update the fields included in the request body. When replacing config, submit the complete config object you want to retain. The following example keeps the existing configuration and adds DuckDB:
config.type when updating an execution environment.
Manage execution environments
List execution environments visible to the caller:include_archived=true to include them.
Archive an execution environment that should no longer be used for new sessions:
204.
Delete an execution environment you no longer need. Only archived execution environments can be deleted; deleting an unarchived environment fails:
204.
Related resources
Sandbox Reference
Review the operating system, preinstalled runtimes and tools, filesystem layout, and network boundaries of cloud sandboxes.
Create a Session
Learn how to create a session and bind an execution environment.