Repository navigation
feat(e2b): run Android and web targets in E2B sandboxes #1598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
71c6fb6
feat(e2b): run Android and web targets in E2B sandboxes
tomasvarga 93b6039
fix(e2b): own each lease in one acquire, and fail fast without Chromium
tomasvarga 59168c0
chore(e2b): raise the @e2e-dev/mobile peer floor to 0.12.6, and e2b d…
tomasvarga 69e7efd
docs(e2b): cut the privacy section to one sentence, and measure the A…
tomasvarga bb9b575
Merge remote-tracking branch 'origin/main' into feat/e2b-provider
tomasvarga 048e53a
test(e2b): count every byte an upgraded socket receives, not only its…
tomasvarga 5e0acbc
docs(e2b): build the browser template from Playwright 1.65.0, as @e2e…
tomasvarga 73aca2e
fix(e2b): stop Android setup at a failed Node download, and test the …
tomasvarga c58cda3
docs(e2b): state the Android start time without 'in our runs'
tomasvarga 8ae9e8c
docs(e2b): shorten the Android start paragraph
tomasvarga dae9995
fix(e2b): name the Android setup step when it outlives its budget
tomasvarga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@e2e-dev/e2b": patch | ||
| --- | ||
|
|
||
| New package: `e2b()`, a device provider that runs Android 16 in one E2B sandbox per worker slot and installs the target's `.apk`, and `e2bBrowsers()` from `@e2e-dev/e2b/web`, a browser provider that runs Chromium in E2B sandboxes per worker slot or per attempt. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import type { E2EConfig } from 'e2e'; | ||
| import { mobile } from '@e2e-dev/mobile'; | ||
| import { e2b } from '@e2e-dev/e2b'; | ||
|
|
||
| export default { | ||
| targets: [ | ||
| { | ||
| name: 'android', | ||
| engine: mobile({ platform: 'android', device: e2b() }), | ||
| app: { bundleId: 'com.example.app', appPath: 'build/app-debug.apk' }, | ||
| }, | ||
| ], | ||
| workers: 4, | ||
| } satisfies E2EConfig; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import type { E2EConfig } from 'e2e'; | ||
| import { web } from '@e2e-dev/web'; | ||
| import { e2bBrowsers } from '@e2e-dev/e2b/web'; | ||
|
|
||
| export default { | ||
| targets: [ | ||
| { | ||
| name: 'e2b-web', | ||
| engine: web({ browser: e2bBrowsers() }), | ||
| app: { url: 'https://staging.example.com' }, | ||
| }, | ||
| ], | ||
| workers: 4, | ||
| } satisfies E2EConfig; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { Template, defaultBuildLogger } from 'e2b'; | ||
|
|
||
| const template = Template().fromImage('mcr.microsoft.com/playwright:v1.65.0-noble'); | ||
| await Template.build(template, 'e2e-chromium', { | ||
| cpuCount: 4, | ||
| memoryMB: 4096, | ||
| onBuildLogs: defaultBuildLogger(), | ||
| }); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| --- | ||
| title: E2B | ||
| sidebarTitle: E2B | ||
| description: Run Android targets and web targets in E2B sandboxes with the e2b() and e2bBrowsers() providers from @e2e-dev/e2b. | ||
| --- | ||
|
|
||
| `@e2e-dev/e2b` runs your targets in [E2B](https://e2b.dev) sandboxes: | ||
| Android 16 with `e2b()`, a [device provider](/mobile#hosted-devices), and | ||
| Chromium with `e2bBrowsers()` from `@e2e-dev/e2b/web`, a | ||
| [browser provider](/browser#hosted-browsers). Your tests stay the same. | ||
|
|
||
| ## Authenticate | ||
|
|
||
| Set `E2B_API_KEY` in the environment that starts e2e. In CI, store it as | ||
| a secret. Copy the key from the [E2B dashboard](https://e2b.dev/dashboard). | ||
| For a dedicated E2B cluster, also set `E2B_DOMAIN`. Without a key, the | ||
| provider fails with `INVALID_CONFIG`. | ||
|
|
||
| ## Run Android targets | ||
|
|
||
| Each worker gets its own Android sandbox, ready with your `.apk` in about | ||
| 15 to 45 seconds. The provider installs the `.apk` through agent-device, | ||
| like `device.installApp()`, and deletes the sandbox when the run ends. | ||
|
|
||
| <Tip> | ||
| No Android SDK, emulator, or `adb` on the machine that runs e2e. | ||
| </Tip> | ||
|
|
||
| Install the integration alongside the mobile engine: | ||
|
|
||
| <CodeGroup> | ||
| ```bash npm | ||
| npm install --save-dev e2e @e2e-dev/mobile @e2e-dev/e2b e2b | ||
| ``` | ||
|
|
||
| ```bash pnpm | ||
| pnpm add -D e2e @e2e-dev/mobile @e2e-dev/e2b e2b | ||
| ``` | ||
|
|
||
| ```bash bun | ||
| bun add -d e2e @e2e-dev/mobile @e2e-dev/e2b e2b | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| Set the target's `device` to `e2b()`: | ||
|
|
||
| ```ts title="e2e.config.ts" | ||
| import type { E2EConfig } from 'e2e'; | ||
| import { mobile } from '@e2e-dev/mobile'; | ||
| import { e2b } from '@e2e-dev/e2b'; | ||
|
|
||
| export default { | ||
| targets: [ | ||
| { | ||
| name: 'android', | ||
| engine: mobile({ platform: 'android', device: e2b() }), | ||
| app: { bundleId: 'com.example.app', appPath: 'build/app-debug.apk' }, | ||
| }, | ||
| ], | ||
| workers: 4, | ||
| } satisfies E2EConfig; | ||
| ``` | ||
|
|
||
| `bundleId` is optional: without it, `app.open()` opens the package that | ||
| agent-device reports for the `.apk`. | ||
|
|
||
| ## Run web targets in browsers | ||
|
|
||
| Each worker gets its own Chromium sandbox, and every attempt gets a new | ||
| browser context in it, as in a local run. With `scope: 'attempt'`, every | ||
| attempt gets a new sandbox instead | ||
| ([limits of that scope](/browser#pick-a-lease-scope)). | ||
|
|
||
| Install the integration alongside the web engine: | ||
|
|
||
| <CodeGroup> | ||
| ```bash npm | ||
| npm install --save-dev e2e @e2e-dev/web @e2e-dev/e2b e2b | ||
| ``` | ||
|
|
||
| ```bash pnpm | ||
| pnpm add -D e2e @e2e-dev/web @e2e-dev/e2b e2b | ||
| ``` | ||
|
|
||
| ```bash bun | ||
| bun add -d e2e @e2e-dev/web @e2e-dev/e2b e2b | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| Build the browser template once, from the Playwright image. Use the image | ||
| tag of the Playwright version your `@e2e-dev/web` uses, and give the | ||
| template 4 GB of memory, as below: | ||
|
|
||
| ```ts title="build-template.ts" | ||
| import { Template, defaultBuildLogger } from 'e2b'; | ||
|
|
||
| const template = Template().fromImage('mcr.microsoft.com/playwright:v1.65.0-noble'); | ||
| await Template.build(template, 'e2e-chromium', { | ||
| cpuCount: 4, | ||
| memoryMB: 4096, | ||
| onBuildLogs: defaultBuildLogger(), | ||
| }); | ||
| ``` | ||
|
|
||
| Then set the target's `browser` to `e2bBrowsers()`. If you named the | ||
| template something else, pass the name as `template`: | ||
|
|
||
| ```ts title="e2e.config.ts" | ||
| import type { E2EConfig } from 'e2e'; | ||
| import { web } from '@e2e-dev/web'; | ||
| import { e2bBrowsers } from '@e2e-dev/e2b/web'; | ||
|
|
||
| export default { | ||
| targets: [ | ||
| { | ||
| name: 'e2b-web', | ||
| engine: web({ browser: e2bBrowsers() }), | ||
| app: { url: 'https://staging.example.com' }, | ||
| }, | ||
| ], | ||
| workers: 4, | ||
| } satisfies E2EConfig; | ||
| ``` | ||
|
|
||
| The browser runs in E2B's cloud, so `app.url` must be reachable from the | ||
| internet, not only from `localhost`. | ||
|
|
||
| ## Android options | ||
|
|
||
| | Option | Default | Meaning | | ||
| | ----------- | -------------- | ------- | | ||
| | `template` | `'android-16'` | Sandbox template that boots Android. | | ||
| | `timeoutMs` | `3600000` (1 hour) | Sandbox lifetime. E2B kills the sandbox after it, even when the run is still using it. | | ||
|
|
||
| ## Browser options | ||
|
|
||
| | Option | Default | Meaning | | ||
| | ----------- | ---------------- | ------- | | ||
| | `template` | `'e2e-chromium'` | Sandbox template with Playwright's Chromium. | | ||
| | `scope` | `'worker'` | `'worker'`: one sandbox per worker slot for the run. `'attempt'`: a new sandbox for every attempt. | | ||
| | `timeoutMs` | `3600000` (1 hour) | Sandbox lifetime. E2B kills the sandbox after it, even when the run is still using it. | | ||
|
|
||
| An unknown option or an invalid value fails with `INVALID_CONFIG` when | ||
| the config loads. | ||
|
|
||
| ## How the sandboxes stay private | ||
|
|
||
| Sandboxes refuse public traffic: the provider reaches each one through a | ||
| tunnel on `127.0.0.1` that adds E2B's access token, and, as with a local | ||
| Chromium, any program on your machine can use that tunnel while the run | ||
| holds the lease. | ||
|
|
||
| ## Limits | ||
|
|
||
| - **Android only.** E2B has no iOS sandboxes, so `e2b()` refuses an iOS | ||
| target. | ||
| - **Android image.** Android 16 on E2B is x86_64 only, without Google Play | ||
| Services, and renders in software. Apps with native libraries need x86_64 | ||
| builds; see [E2B's Android page](https://e2b.dev/docs/use-cases/android). | ||
| The provider installs an `.apk`, not an `.aab`. | ||
| - **Billing.** A sandbox is billed while it runs. Android sandboxes and | ||
| worker-scope browser sandboxes run from the start of the run to its end, | ||
| even while no test uses them; an attempt-scope browser sandbox runs only | ||
| for its attempt. | ||
| - **Stopped runs.** If the runner is killed before it deletes a sandbox, | ||
| E2B deletes it when `timeoutMs` ends. | ||
|
|
||
| ## Next | ||
|
|
||
| <CardGroup cols={2}> | ||
| <Card title="Hosted devices" icon="mobile" href="/mobile#hosted-devices"> | ||
| How a device provider leases devices. | ||
| </Card> | ||
| <Card title="Hosted browsers" icon="globe" href="/browser#hosted-browsers"> | ||
| How a browser provider leases browsers. | ||
| </Card> | ||
| </CardGroup> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.