Skip to content

feat(sandbox): pluggable E2B backend for user scaling (outbound only) #2873

Open

Description

@larryro

Summary

Add an outbound, pluggable E2B execution backend so deployments that need sandbox scale-out can point at E2B Cloud or self-hosted e2b-dev/infra via config — without changing agent/product code.

Default stays Docker / Kubernetes. Tale keeps its own /v1/sessions + runnerd contract; E2B only owns microVM lifecycle/density.

Out of scope: inbound E2B API/envd compatibility (Tale does not expose an E2B-compatible surface). Revisit only if external e2b SDK clients need to target Tale.

Architecture

flowchart LR
  Platform[Platform Convex]
  Spawner[Tale Spawner API]
  Backend{SessionBackend}
  Docker[Docker backend]
  K8s[K8s backend]
  E2B[E2B backend]
  Runnerd[runnerd in box]

  Platform --> Spawner
  Spawner --> Backend
  Backend --> Docker
  Backend --> K8s
  Backend --> E2B
  Docker --> Runnerd
  K8s --> Runnerd
  E2B -->|"Tale runtime template"| Runnerd
Loading

Extension point today: SessionBackend in services/sandbox/src/backend/types.ts (docker | kubernetes), factory in services/sandbox/src/backend/index.ts. Platform client: services/platform/convex/node_only/sandbox/helpers/session_client.ts.

Seam:

  1. Keep Tale contracts: /v1/sessions, runnerd, Convex orchestration
  2. Add SANDBOX_BACKEND=e2b (deployment-level in Phase 1)
  3. E2bSessionBackend uses the official SDK for create/pause/destroy; resolveEndpoint() still points at in-box runnerd
  4. E2B template = @tale/sandbox-runtime (with runnerd) — do not reimplement runnerd on envd in Phase 1

Capability matrix (honesty bar)

Capability E2B backend strategy
exec / files / env / cancel / attach / held-stdin steer Keep via runnerd in template
org quota / admission Stay in Convex; map E2B concurrency/cost separately
LLM gateway virtual keys Keep if gateway is reachable from E2B
Tier-2 per-exec credential overlay Keep
stop/resume workspace Map to E2B pause/resume; align destroy vs stop
egress SSRF fence Do not assume sandbox-egress; E2B network policy or degrade
browser view / screencast Phase 1 degrade/disable (or later Desktop)
DinD Phase 1 unsupported
http://convex/... blob stage Presigned / public URLs required

Phased work

Phase 0 — Contract + matrix

  • Document SessionBackend vs runnerd seam
  • Write E2B capability matrix into services/sandbox/docs/sessions.md
  • Document config: E2B_API_URL / E2B_API_KEY / template id (Cloud and self-host same client)

Phase 1 — MVP (config switch runs agent main path)

  • Implement E2bSessionBackend (create / resolveEndpoint / destroy / stop·pause / list / exists)
  • Package + CI-publish Tale runtime as E2B template
  • Remove Compose-DNS assumptions: presigned blob staging; reachable LLM gateway
  • Integration tests: create → exec → files → pause/resume → destroy
  • Default backend unchanged; E2B opt-in via config

Phase 2 — Scaling product completeness

  • Quotas + cost observability (Convex + E2B)
  • Egress policy docs (Cloud vs self-hosted infra)
  • Browser / DinD: explicit degrade or follow-up
  • Optional: deployment-level sandboxBackend in file config domain (not a new Convex table)

Explicit non-goals

  • Inbound E2B protocol (REST/envd)
  • Replacing Convex session / quota / credential model
  • Platform speaking only the E2B SDK
  • 100% parity with Docker sandbox (DinD, transparent egress, VNC degrade first)
  • Making e2b-dev/infra the default install path (document as optional scale-out)

Risks

  • Network boundary is the largest cost (gateway / blob / callbacks must be reachable from E2B Cloud)
  • Runtime → E2B template publish must be in CI
  • Phase 1 API key + template are deployment-scoped
  • Self-hosted E2B infra is heavy (Terraform / GCP|AWS)

Success criteria

  • Config-only switch: docker/kubernetes ↔ e2b (E2B_API_URL → Cloud or self-host)
  • Coding-agent main path observed green on E2B (create, exec, steer stdin, credential overlay, gateway VK, destroy)
  • Capability degradations documented (and UI-visible where relevant)

References

Activity

  1. added
    priority: medium
    feat
    service: platform
    epic
    on Jul 28, 2026
  2. yannickmonney commented on Nov 14, 2026

    @yannickmonney
    Contributor

    Decision

    Build the E2B backend as a fourth opt-in sandbox backend (SANDBOX_BACKEND=e2b, set per deployment in env). It is outbound-only and lands on main in seven units. Tale keeps /v1/sessions, runnerd and Convex orchestration. E2B owns only the microVM lifecycle, through a full SessionBackend built on the official e2b SDK, which is loaded only when this backend is selected.

    Rules

    • Network boundary: a sandbox never calls Tale over a public URL. The spawner opens one WebSocket per running session into runnerd's new /relay endpoint. Inside the VM, runnerd serves loopback listeners for exactly the two names devices already relay: backend-api:3005 and sandbox-llm-gateway:8080. Requests pass under the device hub's framing and relay-policy.ts allowlist. No presigned URLs, and no public gateway or API.
    • Ingress: every sandbox has allowPublicTraffic=false, secure envd, TLS and the per-session runnerd HMAC token. A root standby script consumes a root-owned 0600 claim file, deletes it and drops to the profile user, as the Incus warm pool does. The token is never in E2B env or metadata.
    • Egress: every create carries an E2B network policy that always denies private, link-local, CGNAT and metadata ranges. SANDBOX_EGRESS_ALLOWLIST is translated only from anchored literal hosts (^a\.b$) and subdomain forms (^(.*\.)?a\.b$); any other regex refuses boot. With an allowlist set, the policy is default-deny plus those domains. SANDBOX_EGRESS_DENIED_HOSTS refuses boot with e2b. A rejected policy fails the create. E2B lets an allowed domain take precedence over the private-range deny; the docs say so and the live suite records it. SANDBOX_E2B_ALLOW_UNFILTERED_NETWORK=true is the only unfiltered mode, and it warns.
    • Lifecycle: stop = pause. E2B's timeout also pauses (onTimeout=pause), and every sweep refreshes it for every live session, so Tale's idle reaper alone decides when a session stops. Resume kills every process left from the old incarnation, then restarts runnerd as a new incarnation. A paused sandbox that E2B no longer has reads as gone. Destroy = kill, reading handed_off. Incarnation and pin live in a root-owned record inside the VM. Run one spawner per E2B key and instance.
    • Config: SANDBOX_E2B_API_KEY, SANDBOX_E2B_DOMAIN (default e2b.app), SANDBOX_E2B_TEMPLATE_AGENT, SANDBOX_E2B_TEMPLATE_DEFAULT, all passed explicitly to the SDK. No file-config key, no new table.

    Answers

    • Seam: runnerd stays in the box. resolveEndpoint widens to {baseUrl, headers?}.
    • Gateway, blob and callbacks: through the relay.
    • Stop/resume: pause/resume, with a process kill on resume. Destroy is the only verb that deletes data.
    • Egress fence: an E2B network policy, failing closed, from a strictly translated allowlist.
    • Browser / screencast: not applicable; already removed.
    • DinD: unsupported; refuses boot, and sessions report docker=false.
    • Quota: Convex plus SANDBOX_MAX_SESSIONS, warned to stay within the E2B team concurrency.
    • Virtual keys and Tier-2 overlay: kept. Tier-0 secrets never enter a sandbox.
    • File-config sandboxBackend: rejected as a duplicate of SANDBOX_BACKEND.

    Rationale
    Layered ingress auth and a relay that reuses the audited device hub, with no wider surface, keep runnerd and Tale's services off the public internet. Egress uses E2B's own policy language: only allowlist forms that translate exactly are accepted, and the precedence caveat is documented. E2B's wall-clock timer must never pause an active turn, and a memory-snapshot resume must not revive the old incarnation's processes. Hence the timeout refresh for all sessions and the kill before runnerd restarts. Turning E2B Cloud on for a deployment Tale operates adds a US sub-processor; that is an activation choice, not a build blocker.

    Units (all on main)

    1. docs(sandbox): E2B contract and capability matrix (S)
    2. refactor(sandbox): runnerd endpoint carries headers; platform and wire accept e2b (M)
    3. feat(sandbox): spawner-held relay into runnerd, on shared tunnel framing (M)
    4. ci(sandbox): build and publish the E2B runtime templates (M)
    5. feat(sandbox): E2B lifecycle and egress policy against a fake E2B API (L)
    6. feat(sandbox): E2B stop/resume, pin and incarnation record (M)
    7. test(sandbox): live E2B e2e, manual box and observability (M)

    Cross-issue amendments (decisions taken together with #4870, #4942):

  3. added
    agent-ready
    on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyepicfeatpriority: mediumservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions