Network policies control outbound network access from a box.
Use them when you want to:
- block all outbound traffic
- allow only specific public domains
- restrict egress to specific CIDR ranges
By default, boxes use:
Modes#
| Mode | Description |
|---|---|
allow-all | Default. No outbound restrictions. |
deny-all | Block all outbound network access. |
custom | Allowlist. Only the listed domains and CIDR ranges are reachable, minus any deniedCidrs. Everything else is blocked. |
The SDK type is:
Create a box with a policy#
Pass networkPolicy when creating a box:
You can also combine domain and CIDR rules:
networkPolicy is also supported in Box.fromSnapshot() and EphemeralBox. A box restored from a snapshot does not inherit the source box’s policy, so pass it again on restore.
Read the current policy#
Use the networkPolicy getter:
Update a running box#
Update the policy after creation:
Switch back to unrestricted outbound access:
Changes take effect immediately. You do not need to recreate the box. updateNetworkPolicy() is not available on EphemeralBox.
Matching rules#
custommode is default-deny: a destination is reachable only if its domain is inallowedDomainsor its resolved IP is inallowedCidrsallowedDomainssupports exact matches such asapi.github.comand must be lowercase- wildcard domains must use
*.suffixform, for example*.githubusercontent.com.*.github.comdoes not matchgithub.comitself allowedCidrsanddeniedCidrsuse standard CIDR notationdeniedCidrsonly removes addresses from what is allowed. A resolved IP in a denied range is blocked even when its domain is inallowedDomains. Acustompolicy with onlydeniedCidrsblocks everything- private IP ranges are always blocked even if you try to allow them explicitly
Example patterns#
Allow only GitHub and npm:
Block all outbound traffic:
Allow a specific public CIDR:
Allow a CIDR range except for a sub-range: