You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: replace outdated ALL_TRAFFIC syntax with selector callbacks (#231)
* made it nicer
* docs: fix updateNetwork wording and add ALL_TRAFFIC backward-compat note
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/sandbox/internet-access.mdx
+48-99Lines changed: 48 additions & 99 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ Every sandbox has access to the internet and can be reached by a public URL.
6
6
7
7
## Controlling internet access
8
8
9
-
You can control whether a sandbox has access to the internet by using the `allowInternetAccess` parameter when creating a sandbox. By default, internet access is enabled (`true`), but you can disable it for security-sensitive workloads.
9
+
You can control whether a sandbox has access to the internet by using the `allowInternetAccess`/ `allow_internet_access`parameter when creating a sandbox. By default, internet access is enabled, but you can disable it for security-sensitive workloads.
When internet access is disabled, the sandbox cannot make outbound network connections, which provides an additional layer of security for sensitive code execution.
33
33
34
34
<Note>
35
-
Setting `allowInternetAccess`to `false`is equivalent to setting `network.denyOut` to `['0.0.0.0/0']` (denying all traffic).
35
+
Setting `allowInternetAccess`/ `allow_internet_access` to a falsy value is equivalent to setting `network.denyOut` / `network.deny_out` to `['0.0.0.0/0']` (denying all traffic).
36
36
</Note>
37
37
38
38
## Fine-grained network control
39
39
40
-
For more granular control over network access, you can use the `network` configuration option to specify allow and deny lists for outbound traffic.
40
+
For more granular control over network access, you can use the network configuration option to specify allow and deny lists for outbound traffic.
41
41
42
42
### Allow and deny lists
43
43
44
44
You can specify IP addresses, CIDR blocks, or domain names that the sandbox is allowed to use:
The selector callback (`({ allTraffic }) => [allTraffic]` / `lambda ctx: [ctx.all_traffic]`) is the recommended way to express "all traffic" (`0.0.0.0/0`). The `ALL_TRAFFIC` constant remains exported for backward compatibility.
87
+
</Note>
88
+
85
89
### Domain-based filtering
86
90
87
-
You can allow traffic to specific domains by specifying hostnames in `allow out`. When using domain-based filtering, you must include `ALL_TRAFFIC`in `deny out` to block all other traffic. Domains are not supported in the `deny out` list.
91
+
You can allow traffic to specific domains by specifying hostnames in `allowOut` / `allow_out`. When using domain-based filtering, you must deny all other traffic in `denyOut` / `deny_out`. Domains are not supported in the deny lists.
88
92
89
93
<CodeGroup>
90
94
```js JavaScript & TypeScript
91
-
import { Sandbox, ALL_TRAFFIC } from'e2b'
95
+
import { Sandbox } from'e2b'
92
96
93
97
// Allow only traffic to google.com
94
98
constsandbox=awaitSandbox.create({
95
99
network: {
96
100
allowOut: ['google.com'],
97
-
denyOut:[ALL_TRAFFIC]
101
+
denyOut:({ allTraffic }) => [allTraffic]
98
102
}
99
103
})
100
104
```
101
105
```python Python
102
-
from e2b import Sandbox, ALL_TRAFFIC
106
+
from e2b import Sandbox
103
107
104
108
# Allow only traffic to google.com
105
109
sandbox = Sandbox.create(
106
110
network={
107
111
"allow_out": ["google.com"],
108
-
"deny_out": [ALL_TRAFFIC]
112
+
"deny_out": lambdactx: [ctx.all_traffic]
109
113
}
110
114
)
111
115
```
@@ -119,24 +123,24 @@ You can also use wildcards to allow all subdomains of a domain:
119
123
120
124
<CodeGroup>
121
125
```js JavaScript & TypeScript
122
-
import { Sandbox, ALL_TRAFFIC } from'e2b'
126
+
import { Sandbox } from'e2b'
123
127
124
128
// Allow traffic to any subdomain of mydomain.com
125
129
constsandbox=awaitSandbox.create({
126
130
network: {
127
131
allowOut: ['*.mydomain.com'],
128
-
denyOut:[ALL_TRAFFIC]
132
+
denyOut:({ allTraffic }) => [allTraffic]
129
133
}
130
134
})
131
135
```
132
136
```python Python
133
-
from e2b import Sandbox, ALL_TRAFFIC
137
+
from e2b import Sandbox
134
138
135
139
# Allow traffic to any subdomain of mydomain.com
136
140
sandbox = Sandbox.create(
137
141
network={
138
142
"allow_out": ["*.mydomain.com"],
139
-
"deny_out": [ALL_TRAFFIC]
143
+
"deny_out": lambdactx: [ctx.all_traffic]
140
144
}
141
145
)
142
146
```
@@ -146,24 +150,24 @@ You can combine domain names with IP addresses and CIDR blocks:
@@ -185,68 +189,41 @@ This is a limitation of how outbound traffic is currently routed from the sandbo
185
189
186
190
### Priority rules
187
191
188
-
When both `allow out`and `deny out` are specified, **allow rules always take precedence** over deny rules. This means if an IP address is in both lists, it will be allowed.
192
+
When both allow and deny rules are specified, **allow rules always take precedence** over deny rules. This means if an IP address is in both lists, it will be allowed.
189
193
190
194
<CodeGroup>
191
195
```js JavaScript & TypeScript
192
-
import { Sandbox, ALL_TRAFFIC } from'e2b'
196
+
import { Sandbox } from'e2b'
193
197
194
-
// Even though ALL_TRAFFIC is denied, 1.1.1.1 and 8.8.8.8 are explicitly allowed
198
+
// Even though all traffic is denied, 1.1.1.1 and 8.8.8.8 are explicitly allowed
195
199
constsandbox=awaitSandbox.create({
196
200
network: {
197
-
denyOut:[ALL_TRAFFIC],
201
+
denyOut:({ allTraffic }) => [allTraffic],
198
202
allowOut: ['1.1.1.1', '8.8.8.8']
199
203
}
200
204
})
201
205
```
202
206
```python Python
203
-
from e2b import Sandbox, ALL_TRAFFIC
207
+
from e2b import Sandbox
204
208
205
-
# Even though ALL_TRAFFIC is denied, 1.1.1.1 and 8.8.8.8 are explicitly allowed
209
+
# Even though all traffic is denied, 1.1.1.1 and 8.8.8.8 are explicitly allowed
206
210
sandbox = Sandbox.create(
207
211
network={
208
-
"deny_out": [ALL_TRAFFIC],
212
+
"deny_out": lambdactx: [ctx.all_traffic],
209
213
"allow_out": ["1.1.1.1", "8.8.8.8"]
210
214
}
211
215
)
212
216
```
213
217
</CodeGroup>
214
218
215
-
### ALL_TRAFFIC helper
216
-
217
-
The `ALL_TRAFFIC` constant represents the CIDR range `0.0.0.0/0`, which matches all IP addresses. Use it to easily deny or allow all network traffic:
218
-
219
-
<CodeGroup>
220
-
```js JavaScript & TypeScript
221
-
import { Sandbox, ALL_TRAFFIC } from'e2b'
222
-
223
-
// Deny all outbound traffic
224
-
constsandbox=awaitSandbox.create({
225
-
network: {
226
-
denyOut: [ALL_TRAFFIC]
227
-
}
228
-
})
229
-
```
230
-
```python Python
231
-
from e2b import Sandbox, ALL_TRAFFIC
232
-
233
-
# Deny all outbound traffic
234
-
sandbox = Sandbox.create(
235
-
network={
236
-
"deny_out": [ALL_TRAFFIC]
237
-
}
238
-
)
239
-
```
240
-
</CodeGroup>
241
-
242
219
### Per-host request transforms
243
220
244
221
<Note>
245
222
Per-host request transforms are currently in private beta.
246
223
If you'd like access, please reach out to us at [support@e2b.dev](mailto:support@e2b.dev).
247
224
</Note>
248
225
249
-
You can register per-host rules under `network.rules` to apply transforms (for example, inject HTTP headers) on outbound requests matching a host. Rules are keyed by host and registering one does **not** grant egress on its own — the host must still be referenced via `allowOut`.
226
+
You can register per-host rules under `network.rules` to apply transforms (for example, inject HTTP headers) on outbound requests matching a host. Rules are keyed by host and registering one does **not** grant egress on its own — the host must still be referenced via `allowOut` / `allow_out`.
250
227
251
228
The `transform.headers` object is sent on the wire as-is and injected by the egress proxy on matching HTTP/HTTPS requests.
252
229
@@ -258,6 +235,9 @@ await Sandbox.create({
258
235
network: {
259
236
// Only allow egress to hosts that have rules registered.
260
237
allowOut: ({ rules }) => [...rules.keys()],
238
+
// Deny all other traffic
239
+
denyOut: ({ allTraffic }) => [allTraffic],
240
+
// Register per-host rules
261
241
rules: {
262
242
'api.example.com': [
263
243
{
@@ -275,7 +255,11 @@ from e2b import Sandbox
275
255
276
256
sandbox = Sandbox.create(
277
257
network={
258
+
# Only allow egress to hosts that have rules registered.
278
259
"allow_out": lambdactx: list(ctx.rules.keys()),
260
+
# Deny all other traffic
261
+
"deny_out": lambdactx: [ctx.all_traffic],
262
+
# Register per-host rules
279
263
"rules": {
280
264
"api.example.com": [
281
265
{
@@ -302,48 +286,13 @@ await Sandbox.create({
302
286
})
303
287
```
304
288
305
-
### Selector callbacks for `allowOut` and `denyOut`
306
-
307
-
`allowOut` and `denyOut` accept either a static list (as shown above) or a **selector callback** that receives a context object — `{ allTraffic, rules }` in JavaScript and `ctx.all_traffic` / `ctx.rules` in Python. This lets you derive policies from the registered rule hosts without duplicating them, and provides a typed alternative to importing `ALL_TRAFFIC`.
308
-
309
-
-`allTraffic` (JS) / `ctx.all_traffic` (Python) is the literal `'0.0.0.0/0'`.
310
-
-`rules` is a `Map` (Python `Mapping`) view of `network.rules`.
The selector form (`({ allTraffic }) => [allTraffic]` / `lambda ctx: [ctx.all_traffic]`) is the recommended way to express "everything". The `ALL_TRAFFIC` constant is still exported for backward compatibility.
338
-
</Note>
339
-
340
289
### Updating network settings on a running sandbox
341
290
342
291
You can update the network configuration of an already running sandbox using `updateNetwork` (JavaScript) or `update_network` (Python). This replaces the current egress rules with the provided configuration without restarting the sandbox.
`updateNetwork` / `update_network`**replaces** the current egress configuration — it does not merge with the existing rules. Calling it with an empty object (`updateNetwork({})` / `update_network({})`) clears all `allowOut` / `denyOut` / per-host rules set at create time.
333
+
`updateNetwork` / `update_network`**replaces** the current egress configuration — it does not merge with the existing rules. Calling it with an empty object (`updateNetwork({})` / `update_network({})`) clears all allow and deny rules set at create time.
385
334
</Note>
386
335
387
-
The create-only options `allowPublicTraffic`and `maskRequestHost` cannot be changed after the sandbox is created.
336
+
Create-only options such as `allowPublicTraffic`/ `allow_public_traffic`, `maskRequestHost` / `mask_request_host` and network rules in `network.rules` cannot be changed after the sandbox is created.
388
337
389
338
## Sandbox public URL
390
339
Every sandbox has a public URL that can be used to access running services inside the sandbox.
@@ -425,7 +374,7 @@ The first leftmost part of the host is the port number we passed to the method.
425
374
426
375
## Restricting public access to sandbox URLs
427
376
428
-
By default, sandbox URLs are publicly accessible. You can restrict access to require authentication using the `allowPublicTraffic` option:
377
+
By default, sandbox URLs are publicly accessible. You can restrict access to require authentication using the `allowPublicTraffic`/ `allow_public_traffic`option:
When `allowPublicTraffic` is set to `false`, all requests to the sandbox's public URLs must include the `e2b-traffic-access-token` header with the value from `sandbox.trafficAccessToken`.
443
+
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`.
495
444
496
445
## Connecting to a server running inside the sandbox
497
446
You can start a server inside the sandbox and connect to it using the approach above.
@@ -587,7 +536,7 @@ Response from server inside sandbox: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
587
536
588
537
## Masking request host headers
589
538
590
-
You can customize the `Host` header that gets sent to services running inside the sandbox using the `maskRequestHost` option. This is useful when your application expects a specific host format.
539
+
You can customize the `Host` header that gets sent to services running inside the sandbox using the `maskRequestHost`/ `mask_request_host`option. This is useful when your application expects a specific host format.
0 commit comments