Skip to main content

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#

ModeDescription
allow-allDefault. No outbound restrictions.
deny-allBlock all outbound network access.
customAllowlist. 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#

  • custom mode is default-deny: a destination is reachable only if its domain is in allowedDomains or its resolved IP is in allowedCidrs
  • allowedDomains supports exact matches such as api.github.com and must be lowercase
  • wildcard domains must use *.suffix form, for example *.githubusercontent.com. *.github.com does not match github.com itself
  • allowedCidrs and deniedCidrs use standard CIDR notation
  • deniedCidrs only removes addresses from what is allowed. A resolved IP in a denied range is blocked even when its domain is in allowedDomains. A custom policy with only deniedCidrs blocks 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: