Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@
"docs/template/examples/expo",
"docs/template/examples/desktop",
"docs/template/examples/claude-code",
"docs/template/examples/docker"
"docs/template/examples/docker",
"docs/template/examples/egress-header"
]
},
"docs/template/migration-v2"
Expand Down
65 changes: 65 additions & 0 deletions docs/template/examples/egress-header.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
title: "Egress header"
description: "Sandbox with automatic HTTP header injection on outbound requests"
---

This template automatically tags every outbound HTTP and HTTPS request from the sandbox with a custom header containing the sandbox ID. No code changes needed — any request your agent makes to external APIs will carry the `X-Sandbox-ID` header transparently.

This enables you to:
- **Track API usage per sandbox** — correlate external API calls back to the sandbox that made them
- **Route traffic** — use the header in your API gateway or proxy to apply per-sandbox rate limits, logging, or access policies
- **Audit agent behavior** — see exactly which external services each sandbox is calling

## How it works

A transparent proxy runs inside the sandbox and intercepts all outbound HTTP/HTTPS traffic. It injects an `X-Sandbox-ID` header into every request before forwarding it to the destination. The sandbox's CA certificate is automatically trusted so HTTPS works without any configuration in Python, Node.js, or any other runtime.

Your code doesn't need to know the proxy exists — it works at the network level.

## Usage

Create a sandbox from the template. Every outbound request automatically includes the `X-Sandbox-ID` header.

<CodeGroup>

```typescript JavaScript & TypeScript
import { Sandbox } from 'e2b'

const sbx = await Sandbox.create('sandbox-egress-header', { timeoutMs: 120_000 })

// Any outbound request from the sandbox will include X-Sandbox-ID
const result = await sbx.commands.run('curl -s https://httpbin.org/headers')
console.log(result.stdout)

await sbx.kill()
```

```python Python
from e2b import Sandbox

sbx = Sandbox.create("sandbox-egress-header", timeout=120)

# Any outbound request from the sandbox will include X-Sandbox-ID
result = sbx.commands.run("curl -s https://httpbin.org/headers")
print(result.stdout)

sbx.kill()
```

</CodeGroup>

The response from httpbin.org shows the injected header:

```json
{
"headers": {
"Accept": "*/*",
"Host": "httpbin.org",
"X-Sandbox-Id": "i3sb4m2knepruowf004y7"
}
}
```

## Source code

The full template source including the proxy addon, startup script, and build configuration is available on [GitHub](https://github.com/e2b-dev/template-examples).