Skip to main content
By default, a sandbox’s public URL is reachable by anyone who knows it. For sensitive workloads, you can require callers to authenticate with a per-sandbox token before any request reaches the services inside.

Restricting public access to sandbox URLs

By default, sandbox URLs are publicly accessible. You can restrict access to require authentication using the allowPublicTraffic / allow_public_traffic option:
When allowPublicTraffic / allow_public_traffic is set to a falsy value, all requests to the sandbox’s public URLs must include the e2b-traffic-access-token header with the value from sandbox.trafficAccessToken / sandbox.traffic_access_token.

Code Interpreter sandboxes

The Code Interpreter server listens on port 49999 and runs any code sent to it. On a sandbox with public access, anyone who has the port 49999 URL can run code in the sandbox and read its files. If you only call the sandbox through the SDK, nothing else needs that URL, so restrict public access. The Code Interpreter SDK sends the traffic access token for you, so runCode / run_code keeps working:

Running a firewall inside the sandbox

E2B already blocks every sandbox from sending outbound traffic to private and link-local address ranges. This is enforced outside the guest, applies to every sandbox, and cannot be disabled, so you do not need your own in-sandbox rules to block these ranges:
  • 10.0.0.0/8
  • 100.64.0.0/10
  • 127.0.0.0/8
  • 169.254.0.0/16
  • 172.16.0.0/12
  • 192.168.0.0/16
E2B’s own control channel to the sandbox runs over an internal address in this space, and its return traffic is accepted before the deny rule is applied, which is why the platform’s own connectivity keeps working. If you add your own blanket outbound drop for one of these ranges (for example iptables -A OUTPUT -d 10.0.0.0/8 -j DROP) without allowing established and related connections ahead of it, you will cut that control channel and the sandbox will lose contact with the SDK. During a template build this surfaces as the start command failing its readiness check.
If you are using custom iptables or firewall rules inside a sandbox, keep E2B’s own connectivity open or the sandbox will lose contact with the SDK:
  • All loopback (lo) traffic.
  • Inbound TCP to port 49983 (the envd control channel).
  • Inbound TCP to port 49999, if you use the Code Interpreter template.
  • Established and related connections, if you filter outbound traffic.
To restrict which public destinations a sandbox can reach, use the built-in network configuration (allowInternetAccess, denyOut, allowOut) rather than in-sandbox firewall rules.