environments
managed-agents/environments
History
managed-agents/environments Changed · +2 / -2 lines
### Packages -The `packages` field pre-installs packages into the sandbox before the agent starts. Packages are installed by their respective package managers and cached across sessions that share the same environment. When multiple package managers are specified, they run in alphabetical order (apt, cargo, gem, go, npm, pip). You can optionally pin specific versions. Unpinned packages install the latest version. +The `packages` field pre-installs packages into the sandbox before the agent starts. Packages are installed by their respective package managers and cached across sessions that share the same environment. When multiple package managers are specified, they run in alphabetical order (apt, cargo, gem, go, npm, pip). You can optionally pin specific versions. Unpinned packages install the latest version. If the environment uses `limited` [networking](https://platform.claude.com/docs/en/managed-agents/environments#networking), also set `networking.allow_package_managers` to `true`; otherwise the request is rejected with a 400 error. <CodeGroup defaultLanguage="CLI"> ```bash cURL
* `allowed_hosts` specifies domains the sandbox can reach. Specify bare hostnames or wildcard patterns (such as `*.example.com`). Do not include a URL scheme, port, or path. * `allow_mcp_servers` allows outbound access to MCP server endpoints configured on the agent, beyond those listed in the `allowed_hosts` array. Defaults to `false`. -* `allow_package_managers` allows outbound access to public package registries (such as PyPI and npm) beyond those listed in the `allowed_hosts` array. Defaults to `false`. +* `allow_package_managers` allows outbound access to public package registries (such as PyPI and npm) beyond those listed in the `allowed_hosts` array. Defaults to `false`. Set it to `true` whenever the environment specifies `packages`; otherwise the request is rejected with a 400 error, even if the registry hosts are listed in `allowed_hosts`. ## Environment lifecycle
managed-agents/environments Changed · +5 / -7 lines
``` ```bash CLI - ant beta:sessions create \ - --agent "$AGENT_ID" \ - --environment-id "$ENVIRONMENT_ID" + ant beta:sessions create --agent "$AGENT_ID" --environment-id "$ENVIRONMENT_ID" ``` ```python Python
| Field | Package manager | Example | | ------- | ------------------------- | ------------------------------------------- | -| `apt` | System packages (apt-get) | `"ffmpeg"` | -| `cargo` | Rust (cargo) | `"[email protected]"` | +| `apt` | System packages (apt-get) | `"graphviz"` | +| `cargo` | Rust (cargo) | `"[email protected]"` | | `gem` | Ruby (gem) | `"rails:7.1.0"` | | `go` | Go modules | `"golang.org/x/tools/cmd/goimports@latest"` | | `npm` | Node.js (npm) | `"[email protected]"` | -| `pip` | Python (pip) | `"pandas==2.2.0"` | +| `pip` | Python (pip) | `"sqlalchemy==2.0.30"` | ### Networking
## Pre-installed runtimes -Cloud sandboxes include common runtimes out of the box. See [Cloud sandbox reference](https://platform.claude.com/docs/en/managed-agents/cloud-sandboxes-reference) for the full list of pre-installed languages, databases, and utilities. +Cloud sandboxes include common language runtimes, databases, and command-line tools out of the box. See [Cloud sandbox reference](https://platform.claude.com/docs/en/managed-agents/cloud-sandboxes-reference) for the full list. ## Next steps
managed-agents/environments Changed · +56 / -34 lines
echo "Environment ID: $environment_id" ``` - ```bash CLI - ant beta:environments create \ - --name "python-dev" \ - --config '{type: cloud, networking: {type: unrestricted}}' - ``` + <MultiFileExample language="cli" label="CLI"> + ```bash CLI + ant beta:environments create < python-dev.environment.yaml + ``` + <File filename="python-dev.environment.yaml"> + ```yaml + name: python-dev + config: + type: cloud + networking: + type: unrestricted + ``` + </File> + </MultiFileExample> + ```python Python environment = client.beta.environments.create( name="python-dev",
) ``` - ```bash CLI - ant beta:environments create <<'YAML' - name: data-analysis - config: - type: cloud - packages: - pip: - - pandas - - numpy - - scikit-learn - npm: - - express - networking: - type: unrestricted - YAML - ``` + <MultiFileExample language="cli" label="CLI"> + ```bash CLI + ant beta:environments create < environment.yaml + ``` + <File filename="environment.yaml"> + ```yaml + name: data-analysis + config: + type: cloud + packages: + pip: + - pandas + - numpy + - scikit-learn + npm: + - express + networking: + type: unrestricted + ``` + </File> + </MultiFileExample> + ```python Python environment = client.beta.environments.create( name="data-analysis",
}' ``` - ```bash CLI - ant beta:environments create <<'YAML' - name: api-access - config: - type: cloud - networking: - type: limited - allowed_hosts: - - api.example.com - allow_mcp_servers: true - allow_package_managers: true - YAML - ``` + <MultiFileExample language="cli" label="CLI"> + ```bash CLI + ant beta:environments create < environment.yaml + ``` + + <File filename="environment.yaml"> + ```yaml + name: api-access + config: + type: cloud + networking: + type: limited + allowed_hosts: + - api.example.com + allow_mcp_servers: true + allow_package_managers: true + ``` + </File> + </MultiFileExample> ```python Python environment = client.beta.environments.create(
managed-agents/environments Changed · +1 / -1 lines
### Networking -The `networking` field controls the sandbox's outbound network access. It does not affect the allowed domains for the `web_search` or `web_fetch` tools. +The `networking` field controls the sandbox's outbound network access. It does not affect the `web_search` or `web_fetch` tools, which run on Anthropic's servers; to restrict the sites those tools can reach, set `allowed_domains` or `blocked_domains` on the tool's entry in the agent toolset. See [Restrict web search and web fetch domains](https://platform.claude.com/docs/en/managed-agents/tools#restrict-web-search-and-web-fetch-domains). | Mode | Description | | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
managed-agents/environments First recorded · 715 lines, first recorded
## Create an environment ## Use the environment in a session ## Configuration options ### Packages ### Networking ## Environment lifecycle ## Manage environments ## Pre-installed runtimes ## Next steps
The first capture of this source. The page was already there, and this is what it said.
---
title: Cloud environment setup
url: https://platform.claude.com/docs/en/managed-agents/environments
description: Customize cloud sandboxes for your sessions.
---
Environments define the sandbox configuration where your agent runs. You create an environment once, then reference its ID each time you start a session. Multiple sessions can share the same environment, but each session gets its own isolated sandbox (a fresh Linux container).
This page covers `type: cloud` environments. To run sandboxes on your own infrastructure, see [Self-hosted sandboxes](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes).
<Note>
Managed Agents API requests require the `managed-agents-2026-04-01` beta header, except memory store endpoints, which use `agent-memory-2026-07-22` instead. The SDK sets the correct beta header automatically. See [Beta headers](https://platform.claude.com/docs/en/api/beta-headers#endpoint-specific-headers).
</Note>
## Create an environment
<CodeGroup defaultLanguage="CLI">
```bash cURL
environment=$(curl -fsS https://api.anthropic.com/v1/environments \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: managed-agents-2026-04-01" \
-H "content-type: application/json" \
--data @- <<'EOF'
{
"name": "python-dev",
"config": {
"type": "cloud",
"networking": {"type": "unrestricted"}
}
}
EOF
)
environment_id=$(jq -r '.id' <<< "$environment")
echo "Environment ID: $environment_id"
```
```bash CLI
ant beta:environments create \
--name "python-dev" \
--config '{type: cloud, networking: {type: unrestricted}}'
```
```python Python
environment = client.beta.environments.create(
name="python-dev",
config={
"type": "cloud",
"networking": {"type": "unrestricted"},
},
)
print(f"Environment ID: {environment.id}")
```
```typescript TypeScript
const environment = await client.beta.environments.create({
name: "python-dev",
config: {
type: "cloud",
networking: { type: "unrestricted" },
},
});
console.log(`Environment ID: ${environment.id}`);
```
```csharp C#
var environment = await client.Beta.Environments.Create(new()
{
Name = "python-dev",
Config = new BetaCloudConfigParams
{
Networking = new BetaUnrestrictedNetwork(),
},
});
Console.WriteLine($"Environment ID: {environment.ID}");
```
```go Go
environment, err := client.Beta.Environments.New(ctx, anthropic.BetaEnvironmentNewParams{
Name: "python-dev",
Config: anthropic.BetaEnvironmentNewParamsConfigUnion{
OfCloud: &anthropic.BetaCloudConfigParams{
Networking: anthropic.BetaCloudConfigParamsNetworkingUnion{
OfUnrestricted: &anthropic.BetaUnrestrictedNetworkParam{},
},
},
},
})
if err != nil {
panic(err)
}
fmt.Printf("Environment ID: %s\n", environment.ID)
```
```java Java
var environment = client.beta().environments().create(EnvironmentCreateParams.builder()
.name("python-dev")
.config(BetaCloudConfigParams.builder()
.networking(BetaUnrestrictedNetwork.builder().build())
.build())
.build());
IO.println("Environment ID: " + environment.id());
```
```php PHP
$environment = $client->beta->environments->create(
name: 'python-dev',
config: ['type' => 'cloud', 'networking' => ['type' => 'unrestricted']],
);
echo "Environment ID: {$environment->id}\n";
```
```ruby Ruby
environment = client.beta.environments.create(
name: "python-dev",
config: {
type: "cloud",
networking: {type: "unrestricted"}
}
)
puts "Environment ID: #{environment.id}"
```
</CodeGroup>
Use a unique, descriptive `name` so you can tell environments apart.
## Use the environment in a session
Pass the environment ID as a string when [creating a session](https://platform.claude.com/docs/en/managed-agents/sessions).
<CodeGroup defaultLanguage="CLI">
```bash cURL
session=$(curl -fsS https://api.anthropic.com/v1/sessions \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: managed-agents-2026-04-01" \
-H "content-type: application/json" \
--data @- <<EOF
{
"agent": "$agent_id",
"environment_id": "$environment_id"
}
EOF
)
```
```bash CLI
ant beta:sessions create \
--agent "$AGENT_ID" \
--environment-id "$ENVIRONMENT_ID"
```
```python Python
session = client.beta.sessions.create(
agent=agent.id,
environment_id=environment.id,
)
```
```typescript TypeScript
const session = await client.beta.sessions.create({
agent: agent.id,
environment_id: environment.id,
});
```
```csharp C#
var session = await client.Beta.Sessions.Create(new()
{
Agent = agent.ID,
EnvironmentID = environment.ID,
});
```
```go Go
session, err := client.Beta.Sessions.New(ctx, anthropic.BetaSessionNewParams{
Agent: anthropic.BetaSessionNewParamsAgentUnion{
OfString: anthropic.String(agent.ID),
},
EnvironmentID: environment.ID,
})
if err != nil {
panic(err)
}
```
```java Java
var session = client.beta().sessions().create(SessionCreateParams.builder()
.agent(agent.id())
.environmentId(environment.id())
.build());
```
```php PHP
$session = $client->beta->sessions->create(
agent: $agent->id,
environmentID: $environment->id,
);
```
```ruby Ruby
session = client.beta.sessions.create(
agent: agent.id,
environment_id: environment.id
)
```
</CodeGroup>
## Configuration options
### Packages
The `packages` field pre-installs packages into the sandbox before the agent starts. Packages are installed by their respective package managers and cached across sessions that share the same environment. When multiple package managers are specified, they run in alphabetical order (apt, cargo, gem, go, npm, pip). You can optionally pin specific versions. Unpinned packages install the latest version.
<CodeGroup defaultLanguage="CLI">
```bash cURL
environment=$(curl -fsS https://api.anthropic.com/v1/environments \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: managed-agents-2026-04-01" \
-H "content-type: application/json" \
--data @- <<'EOF'
{
"name": "data-analysis",
"config": {
"type": "cloud",
"packages": {
"pip": ["pandas", "numpy", "scikit-learn"],
"npm": ["express"]
},
"networking": {"type": "unrestricted"}
}
}
EOF
)
```
```bash CLI
ant beta:environments create <<'YAML'
name: data-analysis
config:
type: cloud
packages:
pip:
- pandas
- numpy
- scikit-learn
npm:
- express
networking:
type: unrestricted
YAML
```
```python Python
environment = client.beta.environments.create(
name="data-analysis",
config={
"type": "cloud",
"packages": {
"pip": ["pandas", "numpy", "scikit-learn"],
"npm": ["express"],
},
"networking": {"type": "unrestricted"},
},
)
```
```typescript TypeScript
const environment = await client.beta.environments.create({
name: "data-analysis",
config: {
type: "cloud",
packages: {
pip: ["pandas", "numpy", "scikit-learn"],
npm: ["express"]
},
networking: { type: "unrestricted" }
}
});
```
```csharp C#
using Anthropic.Models.Beta.Environments;
var environment = await client.Beta.Environments.Create(new()
{
Name = "data-analysis",
Config = new BetaCloudConfigParams
{
Packages = new()
{
Pip = ["pandas", "numpy", "scikit-learn"],
Npm = ["express"],
Cut at 300 lines.