Skip to content

feat(e2b): run Android and web targets in E2B sandboxes - #1598

Merged
okwasniewski merged 11 commits into
e2e-inc:mainfrom
tomasvarga:feat/e2b-provider
Nov 9, 2026
Merged

okwasniewski merged 11 commits into
e2e-inc:mainfrom
tomasvarga:feat/e2b-provider

Conversation

@tomasvarga

@tomasvarga tomasvarga commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What and why

  • New package @e2e-dev/e2b: run targets in E2B sandboxes, as agreed in Official E2B integration: Android devices and web browsers in E2B sandboxes #1414.
    • e2b(): a device provider for the mobile engine. Android 16 on E2B's public android-16 template, one sandbox per worker slot. The .apk is installed through agent-device, like device.installApp().
    • e2bBrowsers() from @e2e-dev/e2b/web: a browser provider for the web engine. Chromium in a sandbox per worker slot, or per attempt.
  • Sandboxes refuse public traffic. A loopback tunnel on the runner (packages/e2b/src/tunnel.ts) adds E2B's traffic token, because the web engine connects with a CDP URL alone and agent-device's client sends no custom header. A lease holds only 127.0.0.1:<port>, so the token never reaches a lease, log, or report.
  • The browser template is built once per E2B team from the Playwright image @e2e-dev/web pins. The docs page has the 8-line script.
flowchart LR
  R[e2e runner] -->|127.0.0.1| T[loopback tunnel]
  T -->|HTTPS + traffic token| E[E2B edge]
  E --> A[agent-device proxy<br/>Android sandbox]
  E --> C[Chromium DevTools<br/>browser sandbox]
Loading
engine: mobile({ platform: 'android', device: e2b() })
engine: web({ browser: e2bBrowsers() })

Issue

Fixes #1414

Verified

Ran it locally: yes

  • Live E2B sandboxes, e2e run against the built packages: Android 16 installs Privacy Friendly 2048 from an .apk, launches it, and swipes; Chromium browses Wikipedia in worker and attempt scope, and reads a download back. No sandbox is left running after a run.
  • The video is the live demo: a chat page where each message is an agent.act step on the same sandbox, Android first, then Chromium.
e2b-e2e-live-demo.mp4

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.

View guided diff

@github-actions github-actions Bot added the size:XXL 1,000+ changed lines, not counting tests, fixtures, translated docs, or the lockfile label Nov 6, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 37 files

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

View guided diff | Re-trigger cubic

Comment thread CONTRIBUTING.md Resolved
Comment thread docs/integrations/e2b.mdx Resolved
Comment thread packages/e2b/src/provider.ts Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 3 files (changes from recent commits).

View guided diff | Re-trigger cubic

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review (agent-run triage).

Thanks @tomasvarga. This is solid work. The package layout, exports, LICENSE/NOTICE and README match the other provider packages, and the tunnel tests use a real upstream server. I found no token leaks. Sandboxes are killed on every setup failure path I could find. I couldn't do a live run because I have no E2B key.

Must fix

  1. The "Chromium missing" error never reaches the user (browsers.ts:57-64, :108-110).
    • The echo ... >&2; exit 1 runs inside a background command whose stderr is dropped. Only the exec line redirects into CHROMIUM_LOG.
    • When I ran the script locally, the message went to stderr and /tmp/e2e-chromium.log was never created.
    • A template without Playwright therefore waits 60s and then fails with "Chromium did not answer through the sandbox tunnel: HTTP 5xx" and no log lines.
    • Run the mkdir and find check in the foreground (sandbox.run), and start only the exec.
  2. Nothing tests that the tunnel binds to loopback only (tunnel.ts:160). If I change '127.0.0.1' to '0.0.0.0', every test still passes, because tunnel.test.ts:79 only matches the URL string. A LAN-reachable proxy that injects the traffic token is the main risk in this design. Assert server.address().address.

Should fix
3. Put lifecycle cleanup in one place. Today it is spread over sandbox.ts:294-351, provider.ts:110-132 and browsers.ts:102-113. Both providers do the same thing: create, open a tunnel to a fixed port, wait until ready, and on failure kill and close.

  • One acquireSandbox({ client, params, port, signal }, ready) could own both resources with a single catch, paired with a release.
  • That removes hold and the serve/connect split.
  • The tunnel doesn't depend on the started process, so it can open right after create.
  1. sandbox.ts (351 lines) mixes concerns: the SDK adapter, env-to-connection mapping, option checks, polling, log tail and lease lifecycle. Splitting it into a client file and a lease file falls out of 3.
  2. agent-device version skew. The sandbox installs the engine's pinned agent-device, but the .apk install goes through this package's own pinned 0.21.36 client. With the peer range @e2e-dev/mobile >=0.11.1, the two can differ: mobile 0.12.0 pins 0.21.25. Raise the mobile floor to the version that pins 0.21.36, or keep the two in lockstep.
  3. Untested guards. Each of these mutations survives:
    • Removing sandbox.kill() when E2B returns no traffic token (sandbox.ts:208). An orphaned sandbox on that path is untested.
    • Removing the 300s setup budget (provider.ts:112).
    • Dropping the WebSocket upgrade's buffered head bytes (tunnel.ts:153).
  4. Docs: cut the "How the sandboxes stay private" section in docs/integrations/e2b.mdx to one sentence. maskRequestHost, Chromium's Host check and the E2B_SANDBOX_URL mechanics are internals. Users need to know one thing: the tunnel listens on 127.0.0.1, and any local program can use it during the run. The E2B_SANDBOX_URL rule already lives in reference/environment.mdx.
  5. Measure "ready in about 15 to 30 seconds" or drop it. Each Android lease downloads Node, runs npm install -g agent-device and boots Android (provider.ts:51-58).

Nits

  • The template example uses memoryMB: 4096, but the prose says "at least 2 GB".
  • browsers.ts:76: Reflect.get(json ?? {}, ...) throws on a primitive JSON body. The retry hides it, but a typed narrowing reads better.
  • The Node tarball downloaded in the sandbox isn't checksum-verified (provider.ts:54).
  • No other package has a contributors field in package.json.
  • The e2b devDependency can go to 2.63.0.

Ran

  • Package tests: 57/57 pass.
  • tsc, oxlint, check:peer-ranges, check:changeset-bumps, check:examples, docs:check, docs:check-errors and check-dist: all clean.
  • The npm pack has 17 files.
  • Mutations: 25 of 30 killed.

Fork CI is waiting on maintainer approval, so the build, test and spec jobs haven't run on this branch.

- One sandboxLeases().acquire creates the sandbox, opens its tunnel, and runs the
  provider's ready step, with a single cleanup that closes the tunnel and kills
  the sandbox; sandbox.ts splits into client.ts (SDK and connection) and lease.ts.
- The browser provider finds Chromium in the foreground, so a template without
  it fails the lease with that message instead of at the start timeout.
- The Node tarball the Android setup downloads is checked against its SHA-256.
- Read the /json/version body with a typed check instead of Reflect.get.
- Tests for the loopback bind, an upgrade's buffered bytes, a sandbox created
  without a traffic token, and the setup budget.
…ev to 2.63.0

0.12.6 is the first @e2e-dev/mobile release that pins agent-device 0.21.36,
the version this package installs builds with.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 10 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread packages/e2b/tests/unit/tunnel.test.ts Resolved
@tomasvarga

Copy link
Copy Markdown
Contributor Author

[claude-opus-5-5] responding on behalf of @tomasvarga

Thanks for the review. All of it is in 93b6039, 59168c0, and 69e7efd (new commits, no force-push).

Must fix

  1. Chromium missing: the lookup now runs in the foreground (sandbox.run), and only the exec is started. A template without Playwright fails the lease at once with exited 1: Playwright Chromium is missing from the sandbox template. Checked live on E2B's base template, plus a unit test.
  2. Loopback bind: tunnel.test.ts now spies on listen and asserts the host and server.address().address are 127.0.0.1. Changing it to 0.0.0.0 fails the test.

Should fix
3. and 4. One sandboxLeases(clientFor).acquire(request, { ...params, port }, ready) in lease.ts creates the sandbox, opens the tunnel right after, runs the provider's ready step, and on any failure closes the tunnel and kills the sandbox in one catch. hold, createAndServe, and the serve/connect split are gone. sandbox.ts is now client.ts (SDK adapter, connection) and lease.ts (lifecycle, polling, log tail, option checks).
5. agent-device skew: the @e2e-dev/mobile peer floor is now >=0.12.6, the first release that pins agent-device 0.21.36, the version this package installs builds with.
6. Untested guards: tests for the kill of a sandbox created without a traffic token, the 300s setup budget (AbortSignal.timeout(300_000)), and the upgrade's buffered head bytes. Each of the three mutations now fails a test.
7. Docs: "How the sandboxes stay private" is one sentence: the tunnel on 127.0.0.1, and any local program can use it during the run. The E2B_SANDBOX_URL rule stays in reference/environment.mdx.
8. Start time: measured on live runs; the docs now say an Android sandbox installs Node and agent-device and boots Android, and was ready in 20 to 45 seconds.

Nits

  • Memory prose now says 4 GB, matching the example.
  • /json/version is read with a typed check instead of Reflect.get.
  • The Node tarball is checked against the SHA-256 nodejs.org publishes before it is unpacked.
  • e2b dev dependency is 2.63.0.
  • contributors: kept. Ten packages have the field, and the vendor-contributed ones list the vendor's people (@e2e-dev/limrun: Limrun's author, @e2e-dev/testmu: two TestMu engineers). Happy to drop it if you prefer.

Verified on this head: 62 unit tests, pnpm check, and live E2B runs: Chromium in worker and attempt scope on the default e2e-chromium template, Android 16 with the 2048 .apk, and the no-Chromium template failing fast. No sandbox left running.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 3 files (changes from recent commits).

View guided diff | Re-trigger cubic

…guards for real

- The Node download, checksum, and unpack run as separate commands, so under
  set -e a failed step stops setup instead of falling through to npm install.
- find's own error no longer comes before the missing-Chromium message.
- Tests: the setup budget ends a lease when it fires, the Chromium lookup's
  shell guard runs in bash, bad Chromium paths are refused, the checksum is
  the exact published one, and the upgrade test sends its bytes as the head.
- Docs: say what the Android start time covers, measured at 15 to 45 seconds.
@tomasvarga

Copy link
Copy Markdown
Contributor Author

[claude-opus-5-5] responding on behalf of @tomasvarga

Follow-ups since my last comment, all new commits:

  • bb9b575 merges main (no rebase). 5e0acbc moves the template example to playwright:v1.65.0-noble, matching chore(deps): bump workspace deps to latest, playwright-core to 1.65.0 #1609.
  • 048e53a: the upgrade test counts every byte upstream receives, for cubic's point. It now corks the request so the bytes arrive as the head.
  • 73aca2e:
    • Android setup runs the Node download, checksum, and unpack as separate commands. Under set -e a failure inside the old && chain fell through to npm install.
    • The tests now exercise the guards for real: the 300s budget ends the lease when it fires, the Chromium shell guard runs in bash, bad Chromium paths are refused, and the checksum is the exact published one.
  • Start time: 15 to 45 seconds is the runner's "mobile engine prepared" line across five live runs (16.7, 20.7, 22.8, 24.8, 43.4 s). That covers creating the sandbox, setup, boot, and the .apk install. The docs now say so.

Re-verified live on 73aca2e: Android, Chromium, and a template without Chromium failing fast.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 6 files (changes from recent commits).

View guided diff | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

View guided diff | Re-trigger cubic

- A setup that hits its 300s budget now fails with what was running, not the
  bare timeout.
- Drop envs from run(), which no caller passes, and the unused files.write
  mock; fix the forwarded-headers comment and the setup script's comment.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 5 files (changes from recent commits).

View guided diff | Re-trigger cubic

@okwasniewski

Copy link
Copy Markdown
Member

Automated re-review (agent-run triage) at dae9995e5.

Every ask from the last review is done:

Ask Status
Chromium-missing error lost Done: FIND_CHROMIUM runs in the foreground via sandbox.run, only exec is started (browsers.ts:62-67,128-129); moving it back to a background start fails the test
Loopback bind untested Done: tunnel.test.ts:94; a 0.0.0.0 bind now fails
One acquire lifecycle Done: sandboxLeases().acquire/release (lease.ts:99-135) with one catch
Split sandbox.ts Done: client.ts (226) + lease.ts (136)
agent-device skew Done: peer floor >=0.12.6, which pins agent-device 0.21.36 like e2b
3 untested guards Done: all killed
Docs internals / 15-30s claim Done: one-sentence privacy note, 15-45s backed by your 5 live runs

e2b tests 66/66, typecheck clean, pnpm check exits 0, tunnel test 25x with no flake. Mutations: 31/38 killed (was 25/30). cubic's last 4 rounds found nothing. Labeling Ready for Human Review; fork CI (build/test/spec) still needs a maintainer to approve the workflow runs.

Optional, non-blocking

  • Both providers repeat rejectUnknownKeys -> templateOption/timeoutOption -> sandboxLeases(...) -> acquire(request, { template, timeoutMs, metadata, port, ... }, ready). Configuring sandboxLeases({ factory, template, timeoutMs, port, maskRequestHost }) once would shrink acquire to (request, metadata, ready), and templateOption/timeoutOption/leaseMetadata/messageOf could leave lease.ts (its header already says "plus the option checks...").
  • The token-less kill in client.ts:150-155 is a second, unbounded sandbox.kill().catch(() => {}); moving the token check into the lease's try block gives one bounded, reported kill.
  • Setup run gets timeoutMs: 300_000, same as the abort signal. If the SDK timeout fires first, the step-naming message from dae9995 is lost. Pass the signal only, or a slightly larger timeoutMs.
  • browsers.test.ts:51 runs the lookup in host bash and assumes /ms-playwright doesn't exist (breaks on a Playwright-image runner or Windows).
  • Surviving mutations: set -eu -> set -u (provider.ts:54, no test runs the setup script), the 60s Chromium start budget (browsers.ts:126), mkdir -p of downloads in FIND_CHROMIUM.
  • Docs say to match the Playwright tag your @e2e-dev/web uses, but the example hardcodes 1.65.0 while the peer floor allows web 0.11.0.

For maintainers: default e2e-chromium template name (users must build it), tunnel throughput through a per-lease Node proxy (unmeasured), no pre-baked Android template (npm install per lease), Sandbox.connect timeoutMs untested, agent-device lockstep going up (e2b pins 0.21.36 exactly; next mobile bump reintroduces skew), contributors field.

@okwasniewski
okwasniewski dismissed their stale review November 7, 2026 16:20

Asks addressed, see re-review comment.

@okwasniewski okwasniewski added the Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. label Nov 7, 2026

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, LGTM!

@okwasniewski
okwasniewski merged commit ae5d121 into e2e-inc:main Nov 9, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. size:XXL 1,000+ changed lines, not counting tests, fixtures, translated docs, or the lockfile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Official E2B integration: Android devices and web browsers in E2B sandboxes

2 participants