Skip to content

A sandbox’s network mode controls where its outbound connections can go. Inbound connections are never allowed; sandboxes publish no ports.

Mode Allowed destinations
public (default) the internet
none nothing, not even a DNS resolver
allowlist a DNS resolver and only the entries you list

In every mode, a sandbox is blocked from reaching the host machine, the host’s local network, and link-local addresses such as cloud metadata services.

Each allowlist entry is one of:

  • a hostname, such as pypi.org;
  • a wildcard subdomain, such as *.pythonhosted.org;
  • an IPv4 address, such as 8.8.8.8;
  • an IPv4 CIDR range, such as 8.8.8.0/24.

A hostname permits the internet addresses returned by the DNS resolver. An allowlist holds at most 256 entries. IPv6 is not supported, and any address or network inside the blocked ranges above is rejected.

In Python and TypeScript, passing allow selects allowlist mode automatically. In Rust, pass SandboxNetwork::Allowlist { allow }.

python/examples/network.py
with Sandbox.create("python:3.12", allow=["pypi.org", "*.pythonhosted.org"]) as sandbox:
installed = sandbox.run(["pip", "install", "--quiet", "six"])
print(installed.exit_code)
sandbox.set_network("none")
refused = sandbox.run(["pip", "download", "--quiet", "--no-deps", "--dest", "/tmp", "idna"])
print(refused.exit_code)
print(sandbox.spec["network"])

Block all outbound traffic, including DNS:

python/examples/network.py
with Sandbox.create("alpine:3.20", network="none") as sandbox:
print(sandbox.run("wget -q -T 5 -O /dev/null http://example.com").exit_code)

Call set_network (setNetwork in TypeScript) to change where new connections can go from that point onward. Already open connections remain open, and the sandbox’s spec reflects the active network setting. Calling it on a sandbox that has ended raises the error for how it ended.

A common pattern is to install dependencies with public or an allowlist, then switch to none before the part you want sealed, as shown above.

dvm records the bytes transferred on every connection as part of the run (What a recording holds).