Skip to main content
A new sandbox cannot reach the public internet. Attach a network policy to allow or deny outbound traffic: a public API, a package registry, or a private host.
Manage policies on the Network Policies page in the console, or with client.network_policies (TypeScript: client.networkPolicies). This is separate from Identity → Providers.

Allow outbound traffic

Use an allowlist when the sandbox must reach both a public API and an internal system:
In the Python SDK, create(..., rules=[...]) creates the policy and adds rules in one call. If a rule fails, the policy is rolled back so you never keep a half-configured policy. For databases and other non-HTTP services, allow the exact port — do not rely on port 443 alone.

What stays blocked

Every new runtime starts with no outbound access: The built-in system default is hidden from the Network Policies list and from list_for_runtime (use include_system=True to see it). It cannot be detached or deleted. Once you attach any network policy of your own, those policies define egress; the system default is only the fallback when nothing else is attached. DNS needed to resolve hostnames still works under restrictive modes. Private / link-local / cloud metadata ranges stay blocked unless you explicitly allowlist that destination — including under allow_all.

Choose a mode

Every policy has an egress mode. Destination rules (host / IP / CIDR + port + protocol) apply to allowlist and denylist. Prefer allowlist for production agents. Use allow_all only when you truly need broad egress. Use denylist when most of the internet is fine but a few hosts must stay blocked.

Name a destination

  • Destination — hostname, IP, or CIDR
  • Port — specific port, or 0 for any port
  • Protocol — tcp, udp, or any

Combine policies

You can attach more than one network policy to a runtime. When that happens, the most restrictive mode wins: Examples:
  • Any attached deny_all → no outbound access.
  • Any allowlist (and no deny_all) → default deny; destinations from attached allowlists are allowed. If a denylist is also attached, overlapping destinations stay denied.
  • Only denylist → outbound allowed except denied destinations.
  • Only allow_all → broad outbound access (sensitive private/metadata ranges still blocked unless explicitly allowed).
Detach the stricter policy to open more traffic. Rule changes apply to a running sandbox.

Reach a registry or a private host

Name every host. A public API and a private database are separate rules. List every destination the workload needs. An allowlist that includes only api.openai.com will block your internal DB — and an allowlist that includes only the DB will block the LLM API. To reach a private database or internal API under allowlist, add an explicit rule for that host (and port).

Attach a policy

Pass network_policy_ids when you create the sandbox, or call attach on a sandbox that is already running. The example below allows api.openai.com and blocks a host that is not on the list.

When you create the sandbox

On a running sandbox

Change a policy

Rename a policy, switch its mode, or add and remove destinations. Changes apply to a running sandbox.

Rename it

Add or remove a destination

Methods

Python methods are on client.network_policies. TypeScript uses client.networkPolicies.

Remove a policy

Keep the list narrow

  1. Stay closed by default — attach a policy only when the sandbox must call out, and prefer allowlist over allow_all.
  2. List every needed destination — public APIs and internal hosts (DB, private API) must each have a rule under allowlist mode.
  3. Keep rules narrow — hostname + exact port beats “any port”; avoid wide CIDRs unless necessary.
  4. Combine with secrets — inject credentials via Store a credential, and only allow the destinations those credentials should talk to.
  5. Detach when unused — remove network policies from idle runtimes; delete unused policies.
Network policies reduce blast radius; they do not stop malicious code from using destinations you intentionally allow. Pair them with least-privilege secrets and human review for high-risk actions.

Next

Expose a web service

An HTTPS URL for an HTTP server inside the runtime

Store a credential

Attach a key as an environment variable

Create Runtime

Attach policies at sandbox create

Endpoints