Skip to content

Commit bcd712b

Browse files
docs: document updateNetwork on running sandboxes (#226)
* docs: document updateNetwork / update_network for running sandboxes
1 parent e313c51 commit bcd712b

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

docs/sandbox/internet-access.mdx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,55 @@ sandbox = Sandbox.create(
229229
```
230230
</CodeGroup>
231231

232+
### Updating network settings on a running sandbox
233+
234+
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.
235+
236+
<CodeGroup>
237+
```js JavaScript & TypeScript
238+
import { Sandbox, ALL_TRAFFIC } from 'e2b'
239+
240+
const sandbox = await Sandbox.create()
241+
242+
// Tighten egress on the running sandbox: block 8.8.8.8
243+
await sandbox.updateNetwork({
244+
denyOut: ['8.8.8.8'],
245+
})
246+
247+
// Replace with an allow-list only
248+
await sandbox.updateNetwork({
249+
denyOut: [ALL_TRAFFIC],
250+
allowOut: ['api.example.com'],
251+
})
252+
253+
// Toggle internet access without recreating the sandbox
254+
await sandbox.updateNetwork({ allowInternetAccess: false })
255+
```
256+
```python Python
257+
from e2b import Sandbox, ALL_TRAFFIC
258+
259+
sandbox = Sandbox.create()
260+
261+
# Tighten egress on the running sandbox: block 8.8.8.8
262+
sandbox.update_network({"deny_out": ["8.8.8.8"]})
263+
264+
# Replace with an allow-list only
265+
sandbox.update_network({
266+
"deny_out": [ALL_TRAFFIC],
267+
"allow_out": ["api.example.com"],
268+
})
269+
270+
# Toggle internet access without recreating the sandbox
271+
sandbox.update_network({"allow_internet_access": False})
272+
```
273+
</CodeGroup>
274+
275+
<Note>
276+
`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.
277+
</Note>
278+
279+
The create-only options `allowPublicTraffic` and `maskRequestHost` cannot be changed after the sandbox is created.
280+
232281
## Sandbox public URL
233282
Every sandbox has a public URL that can be used to access running services inside the sandbox.
234283

0 commit comments

Comments
 (0)