Skip to main content
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.
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()
The response from httpbin.org shows the injected header:
{
  "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.