E2BE2B SDK 2.50 · Code Interpreter 2.10 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
10 small wins to finish your pathNext lesson

Security settings: network, secrets and timeouts

A sandbox isolates code from your systems, not from the internet. For model-written code, turn outbound access off or allow only what is needed.

Examplewith a key
sandbox = Sandbox.create(allow_internet_access=False)

sandbox = Sandbox.create(network={
    "deny_out": lambda ctx: [ctx.all_traffic],
    "allow_out": ["api.your-company.example"],
})
Example
from e2b.sandbox.sandbox_api import SandboxNetworkOpts

for field in SandboxNetworkOpts.__annotations__:
    print(field)

The network options in this SDK version. allow_internet_access=False is the same as denying all outbound traffic. With deny_out set to all traffic, allow_out opens specific addresses or domains. Without it, code that reads a customer's data could post that data anywhere.

Secrets

envs on create or run_code sets environment variables inside the sandbox, and anything the code can read, a prompt-injected model can print. Do not pass database passwords or provider keys in. Give the sandbox the data it needs as files, lesson 6, or use E2B's secrets feature, where a proxy outside the sandbox adds a stored credential to allowed requests without the code ever seeing it.

A checklist for model-written code

  • Outbound network off, or an allow list.
  • No credentials in envs.
  • A short timeout on every run_code, and a sandbox timeout.
  • One sandbox per user or task, killed when done, so one customer's data never sits in another's sandbox.
  • Output size limits before anything goes back to the model.
Try it yourself
  • Print SandboxNetworkOpts.__annotations__["rules"].
  • Find ALL_TRAFFIC in the SDK.
  • Write down which hosts your own agent's code would need.

You understood something today that you didn't yesterday.