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
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
+
<Note>
35
+
Setting `allowInternetAccess` to `false` is equivalent to setting `network.denyOut` to `['0.0.0.0/0']` (denying all traffic).
36
+
</Note>
37
+
38
+
## Fine-grained network control
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.
41
+
42
+
### Allow and deny lists
43
+
44
+
You can specify IP addresses or CIDR blocks that the sandbox can or cannot connect to:
from e2b_code_interpreter import Sandbox, ALL_TRAFFIC
67
+
68
+
# Deny all traffic except specific IPs
69
+
sandbox = Sandbox.create(
70
+
network={
71
+
"deny_out": [ALL_TRAFFIC],
72
+
"allow_out": ["1.1.1.1", "8.8.8.0/24"]
73
+
}
74
+
)
75
+
76
+
# Deny specific IPs only
77
+
restricted_sandbox = Sandbox.create(
78
+
network={
79
+
"deny_out": ["8.8.8.8"]
80
+
}
81
+
)
82
+
```
83
+
</CodeGroup>
84
+
85
+
### Priority rules
86
+
87
+
When both `allowOut` and `denyOut` are specified, **allow rules always take precedence** over deny rules. This means if an IP address is in both lists, it will be allowed.
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`.
247
+
71
248
## Connecting to a server running inside the sandbox
72
249
You can start a server inside the sandbox and connect to it using the approach above.
73
250
@@ -94,6 +271,7 @@ console.log('Response from server inside sandbox:', data);
94
271
awaitprocess.kill()
95
272
```
96
273
```python Python
274
+
import requests
97
275
from e2b_code_interpreter import Sandbox
98
276
99
277
sandbox = Sandbox.create()
@@ -105,16 +283,15 @@ url = f"https://{host}"
105
283
print('Server started at:', url)
106
284
107
285
# Fetch data from the server inside the sandbox.
108
-
response =sandbox.commands.run(f"curl {url}")
109
-
data = response.stdout
110
-
print("Response from server inside sandbox:", data)
286
+
response =requests.get(url)
287
+
data = response.text
288
+
print('Response from server inside sandbox:', data)
111
289
112
290
# Kill the server process inside the sandbox.
113
291
process.kill()
114
292
```
115
293
</CodeGroup>
116
294
117
-
118
295
This output will look like this:
119
296
<CodeGroup>
120
297
```bash JavaScript & TypeScript
@@ -158,3 +335,39 @@ Response from server inside sandbox: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
158
335
</html>
159
336
```
160
337
</CodeGroup>
338
+
339
+
340
+
## Masking request host headers
341
+
342
+
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.
343
+
344
+
<CodeGroup>
345
+
```js JavaScript & TypeScript
346
+
import { Sandbox } from'@e2b/code-interpreter'
347
+
348
+
// Create sandbox with custom host masking
349
+
constsandbox=awaitSandbox.create({
350
+
network: {
351
+
maskRequestHost:'localhost:${PORT}'
352
+
}
353
+
})
354
+
355
+
// The ${PORT} variable will be replaced with the actual port number
356
+
// Requests to the sandbox will have Host header set to for example: localhost:8080
357
+
```
358
+
```python Python
359
+
from e2b_code_interpreter import Sandbox
360
+
361
+
# Create sandbox with custom host masking
362
+
sandbox = Sandbox.create(
363
+
network={
364
+
"mask_request_host": "localhost:${PORT}"
365
+
}
366
+
)
367
+
368
+
# The ${PORT} variable will be replaced with the actual port number
369
+
# Requests to the sandbox will have Host header set to for example: localhost:8080
370
+
```
371
+
</CodeGroup>
372
+
373
+
The `${PORT}` variable in the mask will be automatically replaced with the actual port number of the requested service.
0 commit comments