Documentation
¶
Overview ¶
Package api holds the HTTP-facing glue for edvabe: dispatch router, reverse proxy, and (later) the control-plane handlers.
Index ¶
- Constants
- func NewProxy(lookup SandboxLookup, resolver AgentResolver) http.Handler
- func NewRouter(control, proxy, dashboard http.Handler) http.Handler
- func RequireAPIKey(next http.Handler) http.Handler
- func WriteError(w http.ResponseWriter, code int, message string)
- type AgentResolver
- type SandboxLookup
Constants ¶
const ( // HeaderSandboxID is the header the E2B SDKs send on every // data-plane request. Carries the sandbox ID the reverse proxy // should forward to. HeaderSandboxID = "E2b-Sandbox-Id" // HeaderSandboxPort identifies which in-sandbox service the SDK // wants to talk to (49983 = envd, 49999 = code interpreter overlay, // anything else = user service). Phase 1 only routes envd. HeaderSandboxPort = "E2b-Sandbox-Port" )
Variables ¶
This section is empty.
Functions ¶
func NewProxy ¶
func NewProxy(lookup SandboxLookup, resolver AgentResolver) http.Handler
NewProxy returns an http.Handler that forwards requests carrying an E2b-Sandbox-Id header to the in-sandbox agent. The handler:
- looks the sandbox up via SandboxLookup (404 if unknown)
- resolves the agent endpoint via AgentResolver (500 on failure)
- reverse-proxies the request with FlushInterval: -1 so Connect-RPC server-stream frames reach the client immediately rather than being buffered until the response closes.
Hop-by-hop header stripping is handled by httputil.ReverseProxy's own transport layer — we don't need to touch Connection/Upgrade/etc. explicitly. The request body is never read by edvabe; it flows through as a stream.
func NewRouter ¶
NewRouter dispatches incoming requests to either the control-plane handler or the sandbox reverse proxy.
A request belongs to the proxy if it carries E2b-Sandbox-Id in the headers or if its Host header has the "<port>-<id>.<domain>" layout that the SDKs fall back to when headers aren't an option (legacy clients, browser-side code). If we resolve the sandbox from the host, the headers are populated so the proxy handler doesn't have to re-parse the host. Requests with neither go to the control plane unchanged.
func RequireAPIKey ¶
RequireAPIKey accepts any non-empty X-API-Key and rejects missing keys with the standard E2B error envelope.
func WriteError ¶
func WriteError(w http.ResponseWriter, code int, message string)
WriteError writes the E2B-compatible control-plane error envelope.
Types ¶
type AgentResolver ¶
AgentResolver turns a sandbox ID into the host:port of its in-sandbox agent. Satisfied by runtime.Runtime in production.
type SandboxLookup ¶
SandboxLookup is the subset of sandbox.Manager the proxy needs. Declaring it as an interface here lets tests inject a fake lookup without constructing a full Manager, and documents the minimal contract required for future proxy backends.