Skip to main content
Kimi Hosted Agents provides two types of execution environments: platform-managed cloud environments and self-hosted environments. Every session must be bound to an execution environment via 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 a POST /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:
The response includes the environment’s 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, set config.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 under packages, 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

The networking 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_hosts fall into two categories. Domain entries support exact hostnames and *.example.com wildcards (matching subdomains at any depth, excluding the apex domain itself) and may include a port (such as api.example.com:8443). If you omit the port, only ports 80 and 443 are allowed. IP address and CIDR block entries (such as 1.2.3.4 or 10.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 as https://) or a path. You can configure at most 128 entries; invalid entries are rejected with HTTP 400 when creating or updating the execution environment.
  • allow_mcp_servers controls whether to additionally allow access to MCP server endpoints configured on the agent. Defaults to false.
  • allow_package_managers controls whether to additionally allow access to public package registries such as PyPI and npm. Defaults to false.
Both modes support configuring 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.
For production workloads, explicitly set networking.type to limited and follow the principle of least privilege by allowing only the hosts your agent actually needs. Omitting networking uses unrestricted mode.

Setup script

Use setup_script for one-time preparation tasks such as creating directories or generating configuration files.

Use in a session

Pass environment_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 until build_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 a PATCH /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:
The platform saves the updated configuration as a new version and builds it asynchronously. New versions do not affect existing sessions, and you cannot change config.type when updating an execution environment.

Manage execution environments

List execution environments visible to the caller:
Archived environments are excluded by default. Pass include_archived=true to include them. Archive an execution environment that should no longer be used for new sessions:
Archiving cannot be undone. An archived environment cannot be used to create new sessions, while existing sessions remain unaffected. A successful archive request returns HTTP 204. Delete an execution environment you no longer need. Only archived execution environments can be deleted; deleting an unarchived environment fails:
Deletion also fails if any non-terminated sessions still reference the environment. A successful delete request returns HTTP 204.

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.