Outbound network rules
Give a sandbox no internet, or only the domains and IP ranges you list.
By default a sandbox can reach the whole internet. With a network rule you choose what it can reach: nothing at all, or only the domains and IPv4 ranges you list. This is how you run code you don't trust, or an AI agent that should only talk to the services it needs.
The rule is enforced on the host, outside the sandbox. Code running as root inside the sandbox cannot change or remove it.
Set it when you create a sandbox
Add network to the create body:
{
"template": "code-interpreter",
"network": { "allow_out": ["pypi.org", "*.pythonhosted.org"] }
}network | What the sandbox can reach |
|---|---|
| not sent | Everything (the default, unchanged) |
{ "allow_out": [] } | Nothing |
{ "allow_out": ["github.com", "*.githubusercontent.com"] } | Only these names |
{ "allow_out": ["10.0.0.0/8", "203.0.113.7"] } | Only these IPv4 ranges and addresses |
{ "allow_out": ["*.example.com"], "deny_out": ["admin.example.com"] } | Every subdomain of example.com except one |
{ "allow_out": ["*"] } | Everything (same as not sending a rule) |
How entries match:
github.comallows exactly that name, not its subdomains.*.example.comallows every name underexample.com, at any depth, but notexample.comitself. List both if you need both.- An IPv4 address or range (
203.0.113.7,10.0.0.0/8) allows connections to it directly, with no DNS lookup. deny_outtakes names only, and wins overallow_out. It cannot be combined with"*": an "everything" rule allows every address, so a denied name would still be reachable by its IP.- Up to 512 entries.
A fork or fork tree of a sandbox with a rule keeps that rule. A new sandbox made from a snapshot (from_snapshot) takes the network of its own create request.
Read or change it later
GET /v1/sandboxes/{id}/network
PUT /v1/sandboxes/{id}/networkPUT takes the same object as network on create and returns the rule as stored:
curl -X PUT https://api.pandastack.ai/v1/sandboxes/$ID/network \
-H "Authorization: Bearer $PANDASTACK_API_KEY" \
-d '{"allow_out": ["github.com"]}'A change works on a running or a sleeping sandbox, and does not wake a sleeping one. It applies to new connections; a connection that is already open stays open. Send {"allow_out": ["*"]} to remove the rule.
What the sandbox sees
- A name that is not allowed does not resolve: DNS answers
REFUSED, so tools say they could not resolve the host. - A connection to an address that is not allowed is refused at once (TCP reset), rather than hanging until a timeout.
- DNS works the same as always. The sandbox may use any DNS server; the lookup is answered by PandaStack's checker on the host.
Limits
- A rule allows an address, not a website. If an allowed name shares an IP address with another site (a CDN or a shared host), that other site is reachable too.
- An address learned from DNS stays allowed for at least 10 minutes and at most an hour, so a program that keeps a connection pool keeps working.
- IPv6 is not routed to sandboxes, with or without a rule.
- Inbound traffic is not affected: preview URLs,
exec, the terminal and file access work as before.