Containers, Agents - Secure credential injection and dynamic egress policies for Sandboxes
Key Points
- Zero-trust credential injection without exposing secrets
- Per-instance ephemeral TLS interception with sandbox-trusted CA
- Runtime-changeable egress policies via outbound handlers
Summary
Cloudflare added zero-trust outbound controls for Sandboxes and Containers: outbound Workers can inject credentials, perform TLS interception with per-instance ephemeral CAs, enforce allow/deny host lists, and apply dynamic per-instance egress policies. Secrets and ephemeral private keys never enter the sandbox; outbound handlers run outside the container runtime and attach auth transparently. Handlers can be changed at runtime without restarting the sandbox.
Key Points
- Credential injection: outbound handlers run in the Workers runtime and can attach secrets to requests without exposing tokens to sandboxed workloads. Use
ctx.containerIdto fetch per-instance credentials. - TLS interception: each sandbox instance gets a unique ephemeral CA (trusted inside the sandbox); the private key never leaves the runtime sidecar, enabling transparent HTTPS proxying.
- Host filtering: use
allowedHosts(deny-by-default allowlist) anddeniedHosts; both support glob patterns for matching. - Dynamic handlers: define named handlers in
outboundHandlersand apply or change them at runtime withsetOutboundHandler()orsetOutboundByHost()to modify egress without restarting the sandbox. - Handler params: outbound handlers accept
paramsso you can customize behavior per instance without creating new handler functions. - Upgrade: install
@cloudflare/containers@0.3.0or@cloudflare/sandbox@0.8.9to enable these features.
Practical Notes for Engineers
- Store and rotate secrets in the Worker environment; rotated secrets are picked up immediately by outbound handlers.
- Use
ctx.containerIdto map instance-specific keys (e.g., per-repo or per-user credentials) and avoid embedding secrets in sandboxed code. - Apply a permissive handler for setup (e.g.,
allowHosts) and switch to a restrictive handler (e.g.,noHttp) after initialization usingawait sandbox.setOutboundHandler().
Links
- See docs: Sandbox outbound traffic and Container outbound traffic for full examples and API details.