Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/e2b-provider.md
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.
16 changes: 16 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,22 @@ suites that consume the built packages the way a user would.
engine (`DeviceProvider`), through agent-device's built-in `browserstack`
provider. An `https` `app` is uploaded once per run through the App
Automate API, since the session's `app` capability takes only `bs://` ids.
- `packages/e2b` — the published `@e2e-dev/e2b` package: E2B sandboxes for
both engines, through the `e2b` SDK (peer). Every sandbox refuses public
traffic; a loopback tunnel on the runner (`src/tunnel.ts`) adds E2B's
traffic access token, and a lease names only that tunnel, so no lease
carries that token. `e2b()` (`DeviceProvider`) boots one `android-16`
sandbox per worker slot, installs the engine's agent-device there behind
`agent-device proxy`, and installs the target's `.apk` through that proxy
with the agent-device client (pinned like `@e2e-dev/mobile`'s); the lease's
`daemon` is the tunnel, so the runner needs no `adb`. `e2bBrowsers()` from
`@e2e-dev/e2b/web` (`BrowserProvider`) starts Chromium on a sandbox's
loopback and creates the sandbox with `maskRequestHost`, so E2B's edge
rewrites `Host` to `localhost` and DevTools accepts the request. Keep the
Playwright image in `docs/examples/web/e2b-template.ts` in sync with
`@e2e-dev/web`. Run
`pnpm --filter @e2e-dev/e2b test`, then verify live sandboxes on both
engines, web in both scopes, with `E2B_API_KEY` set.
- `apps/testbed` (`@e2e-dev/testbed`, private) — dogfood project that
consumes the **built** packages like a real user would: the playground app
where every runner feature (sessions, routes, downloads, frames, uploads,
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,5 +331,5 @@ build against, and what a third-party engine builds against too. A change to
that contract bumps all three packages together in one release, with a
changeset for each, so an engine and a runner from the same release always
match. Engines declare a peer range on `e2e` that points one way only
(engine to runner, `>=x <1`), and each integration (`@e2e-dev/kernel`, `@e2e-dev/lightpanda`, `@e2e-dev/eas`, `@e2e-dev/smol`, `@e2e-dev/testmu`, `@e2e-dev/browserstack`) does
(engine to runner, `>=x <1`), and each integration (`@e2e-dev/kernel`, `@e2e-dev/lightpanda`, `@e2e-dev/eas`, `@e2e-dev/smol`, `@e2e-dev/testmu`, `@e2e-dev/browserstack`, `@e2e-dev/e2b`) does
Comment thread
tomasvarga marked this conversation as resolved.
Resolved
the same on the engines it plugs into; do not make it mutual or narrow it.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Flutter, and .NET MAUI, each a standalone project with a passing suite.
| [`@e2e-dev/lightpanda`](https://www.npmjs.com/package/@e2e-dev/lightpanda) | Lightpanda, the open-source headless browser, started per run for the web engine. |
| [`@e2e-dev/smol`](https://www.npmjs.com/package/@e2e-dev/smol) | smol machines browsers for the web engine: by default, each attempt branches a warm Chromium microVM. |
| [`@e2e-dev/testmu`](https://www.npmjs.com/package/@e2e-dev/testmu) | TestMu AI (formerly LambdaTest) hosted Android emulators, iOS simulators, and real devices for the mobile engine, and hosted Chrome and Edge for the web engine. |
| [`@e2e-dev/e2b`](https://www.npmjs.com/package/@e2e-dev/e2b) | E2B sandboxes: Android 16 for the mobile engine, and Chromium for the web engine. |
| [`@e2e-dev/browserstack`](https://www.npmjs.com/package/@e2e-dev/browserstack) | BrowserStack App Automate real Android and iOS devices for the mobile engine. |
| [`@e2e-dev/limrun`](https://www.npmjs.com/package/@e2e-dev/limrun) | Limrun hosted iOS simulators and Android emulators for mobile tests. |
| [`@e2e-dev/eas`](https://www.npmjs.com/package/@e2e-dev/eas) | Expo Simulators hosted iOS simulators and Android emulators for the mobile engine. |
Expand Down
1 change: 1 addition & 0 deletions docs/browser.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ when the run no longer uses it.
| [smol machines](/integrations/smol) microVMs on your own computer | `smol()` from `@e2e-dev/smol` |
| [Lightpanda](/integrations/lightpanda), the open-source headless browser, on your own machine | `lightpanda()` from `@e2e-dev/lightpanda` |
| [TestMu AI](/integrations/testmu#run-web-targets-in-browsers) | `testmuBrowsers()` from `@e2e-dev/testmu/web` |
| [E2B](/integrations/e2b#run-web-targets-in-browsers) sandboxes | `e2bBrowsers()` from `@e2e-dev/e2b/web` |
| Any other service | Your own provider, a few dozen lines in your project |

When the service shows the window in a live view, add `viewport: null` so
Expand Down
3 changes: 2 additions & 1 deletion docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@
"integrations/smol",
"integrations/limrun",
"integrations/testmu",
"integrations/browserstack"
"integrations/browserstack",
"integrations/e2b"
]
},
{
Expand Down
14 changes: 14 additions & 0 deletions docs/examples/mobile/e2b.config.ts
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;
14 changes: 14 additions & 0 deletions docs/examples/web/e2b-browsers.config.ts
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;
8 changes: 8 additions & 0 deletions docs/examples/web/e2b-template.ts
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(),
});
1 change: 1 addition & 0 deletions docs/images/integrations/e2b.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
180 changes: 180 additions & 0 deletions docs/integrations/e2b.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
---
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. The provider installs your
`.apk` through agent-device, the same way `device.installApp()` does, and
deletes the sandbox when the run ends. Each sandbox installs Node and
agent-device and boots Android, so preparing the target (creating the
sandbox, that setup, and installing the `.apk`) took 15 to 45 seconds in
our runs.

<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>
3 changes: 3 additions & 0 deletions docs/integrations/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Only the target's `browser` or `device` in the config changes.
<Card title="BrowserStack" icon="/images/integrations/browserstack.svg" href="/integrations/browserstack">
`@e2e-dev/browserstack`: BrowserStack App Automate real Android and iOS devices for mobile targets.
</Card>
<Card title="E2B" icon="/images/integrations/e2b.svg" href="/integrations/e2b">
`@e2e-dev/e2b`: Android 16 sandboxes for mobile targets, and Chromium sandboxes for web targets.
</Card>
</CardGroup>

## Use a service with no integration
Expand Down
3 changes: 2 additions & 1 deletion docs/mobile.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ run starts, and releases it when the run ends.
For [Expo Simulators](/integrations/eas), use `expoSimulators()` from
`@e2e-dev/eas`. For [TestMu AI](/integrations/testmu), use `testmu()` from
`@e2e-dev/testmu`. For [BrowserStack](/integrations/browserstack), use
`browserstack()` from `@e2e-dev/browserstack`. For another service, write a provider of a few dozen lines,
`browserstack()` from `@e2e-dev/browserstack`. For Android on [E2B](/integrations/e2b), use `e2b()` from
`@e2e-dev/e2b`. For another service, write a provider of a few dozen lines,
such as `hostedDevices` in the example below:

```ts
Expand Down
2 changes: 2 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
"@ai-sdk/typesafe-ai": "3.0.34",
"@e2e-dev/browserstack": "workspace:*",
"@e2e-dev/decision": "workspace:*",
"@e2e-dev/e2b": "workspace:*",
"@e2e-dev/limrun": "workspace:*",
"@e2e-dev/mobile": "workspace:*",
"@e2e-dev/testmu": "workspace:*",
"@e2e-dev/web": "workspace:*",
"@openrouter/ai-sdk-provider": "3.1.0",
"@types/node": "26.6.6",
"ai": "7.0.164",
"e2b": "2.63.0",
"e2e": "workspace:*",
"typescript": "7.0.2",
"zod": "4.6.7"
Expand Down
4 changes: 4 additions & 0 deletions docs/reference/environment.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ What is sent and how to read it is on the [Telemetry](/telemetry) page.
| `BROWSERSTACK_API_ENDPOINT` | `BROWSERSTACK_API_ENDPOINT=<url>` | value | The App Automate API base URL `browserstack()` uploads `https` builds to and looks up session recordings at. Default `https://api-cloud.browserstack.com/app-automate`. A value that is not an http(s) URL, or carries a username or password, fails with `INVALID_CONFIG` |
| `LT_USERNAME`, `LT_ACCESS_KEY` | `LT_USERNAME=acme` | value | The TestMu AI username and access key `testmu()` from `@e2e-dev/testmu` leases devices with. With either unset, the device lease fails. `testmuBrowsers()` from `@e2e-dev/testmu/web` puts them only in the CDP URL of each browser session, and with either unset the browser lease fails. See [TestMu AI](/integrations/testmu) |
| `TESTMU_API_ENDPOINT` | `TESTMU_API_ENDPOINT=<url>` | value | The TestMu AI sessions API base URL `testmu()` looks up session recordings at. Default `https://mobile-api.lambdatest.com/mobile-automation/api/v1`. A value that is not an http(s) URL, or carries a username or password, fails the lookup with `INVALID_CONFIG`. agent-device's TestMu AI plugin reads it too |
| `E2B_API_KEY` | `E2B_API_KEY=<key>` | value | The API key `e2b()` from `@e2e-dev/e2b` and `e2bBrowsers()` from `@e2e-dev/e2b/web` create sandboxes with. Unset, the lease fails with `INVALID_CONFIG`. See [E2B](/integrations/e2b) |
| `E2B_DOMAIN` | `E2B_DOMAIN=e2b.example.com` | value | The E2B domain the providers create sandboxes on. Default `e2b.app`. Set it for a dedicated E2B cluster |
| `E2B_API_URL` | `E2B_API_URL=<url>` | value | The E2B API URL the providers call. Default `https://api.<E2B_DOMAIN>` |
| `E2B_SANDBOX_URL` | `E2B_SANDBOX_URL=<url>` | value | The URL the providers send sandbox commands and uploads to. Default: the E2B SDK builds it from `E2B_DOMAIN`. If the shell that starts e2e sets it, the run's environment must set the same value, or the lease fails with `INVALID_CONFIG` |
| `E2E_WEB_BROWSERS_<TARGET>_<digest>` | - | value | `@e2e-dev/web` writes it in `prepare`; each worker reads it to find its leased browser. Don't set it by hand |
| `E2E_AGENT_DEVICE_POOL_<TARGET>_<digest>` | - | value | `@e2e-dev/mobile` writes it in `prepare`; each worker reads it to find its booted device. Don't set it by hand |

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"type": "module",
"scripts": {
"build": "pnpm --filter e2e run build && pnpm --filter @e2e-dev/web run build && pnpm --filter @e2e-dev/mobile run build && pnpm --filter @e2e-dev/github run build && pnpm --filter @e2e-dev/kernel run build && pnpm --filter @e2e-dev/lightpanda run build && pnpm --filter @e2e-dev/eas run build && pnpm --filter @e2e-dev/smol run build && pnpm --filter @e2e-dev/limrun run build && pnpm --filter @e2e-dev/decision run build && pnpm --filter @e2e-dev/testmu run build && pnpm --filter @e2e-dev/acp run build && pnpm --filter @e2e-dev/browserstack run build",
"build": "pnpm --filter e2e run build && pnpm --filter @e2e-dev/web run build && pnpm --filter @e2e-dev/mobile run build && pnpm --filter @e2e-dev/github run build && pnpm --filter @e2e-dev/kernel run build && pnpm --filter @e2e-dev/lightpanda run build && pnpm --filter @e2e-dev/eas run build && pnpm --filter @e2e-dev/smol run build && pnpm --filter @e2e-dev/limrun run build && pnpm --filter @e2e-dev/decision run build && pnpm --filter @e2e-dev/testmu run build && pnpm --filter @e2e-dev/acp run build && pnpm --filter @e2e-dev/browserstack run build && pnpm --filter @e2e-dev/e2b run build",
"check": "pnpm run lint && pnpm run check:dead-code && pnpm run typecheck && pnpm run docs:check-errors && pnpm run check:peer-ranges && pnpm run check:changeset-bumps && pnpm run check:examples && pnpm run check:install-scripts && pnpm run plugins:check && pnpm run mcp-server:check && pnpm run docs:check",
"check:dead-code": "fallow dead-code",
"check:peer-ranges": "node scripts/check-peer-ranges.ts",
Expand All @@ -30,7 +30,7 @@
"canary": "node scripts/canary-changeset.ts && changeset version --snapshot canary && pnpm run build",
"canary:publish": "changeset publish --tag canary --no-git-tag && node scripts/restore-peer-ranges.ts",
"typecheck": "pnpm run build && pnpm -r run typecheck && tsc -p scripts",
"test": "pnpm run build && pnpm --filter e2e run test && pnpm --filter @e2e-dev/web run test && pnpm --filter @e2e-dev/mobile run test && pnpm --filter @e2e-dev/github run test && pnpm --filter @e2e-dev/kernel run test && pnpm --filter @e2e-dev/lightpanda run test && pnpm --filter @e2e-dev/eas run test && pnpm --filter @e2e-dev/smol run test && pnpm --filter @e2e-dev/limrun run test && pnpm --filter @e2e-dev/decision run test && pnpm --filter @e2e-dev/acp run test && pnpm run test:scripts && pnpm --filter @e2e-dev/testmu run test && pnpm --filter @e2e-dev/browserstack run test",
"test": "pnpm run build && pnpm --filter e2e run test && pnpm --filter @e2e-dev/web run test && pnpm --filter @e2e-dev/mobile run test && pnpm --filter @e2e-dev/github run test && pnpm --filter @e2e-dev/kernel run test && pnpm --filter @e2e-dev/lightpanda run test && pnpm --filter @e2e-dev/eas run test && pnpm --filter @e2e-dev/smol run test && pnpm --filter @e2e-dev/limrun run test && pnpm --filter @e2e-dev/decision run test && pnpm --filter @e2e-dev/acp run test && pnpm run test:scripts && pnpm --filter @e2e-dev/testmu run test && pnpm --filter @e2e-dev/browserstack run test && pnpm --filter @e2e-dev/e2b run test",
"test:testbed": "pnpm run build && pnpm --filter @e2e-dev/testbed test",
"test:web-benchmark": "pnpm run build && pnpm --filter @e2e-dev/web-benchmark test",
"test:mobile-benchmark": "pnpm run build && pnpm --filter @e2e-dev/mobile-benchmark test",
Expand Down
Loading