Architecture
This example combines two services:- E2B Sandbox — a secure cloud environment where the web app runs. E2B exposes the app at a public HTTPS URL via
sandbox.get_host(port). - Kernel Cloud Browser — a remote Chromium instance controlled through Playwright’s CDP protocol. It navigates the public URL, takes screenshots, and collects page metadata.
Prerequisites
- An E2B API key
- A Kernel API key
- Python 3.10+
.env
How it works
Create the sandbox
Start an E2B sandbox using the
kernel-browser template, which comes with the Kernel SDK and Playwright client pre-installed. No local browser binary is needed — Kernel provides the browser remotely.Deploy the web app
Write a FastAPI application into the sandbox and start it as a background process on port 8000.
Browse with Kernel
A script running inside the sandbox creates a Kernel cloud browser, connects via Playwright CDP, and visits each route to take screenshots.
Full example
app_preview.py
Key concepts
| Concept | Detail |
|---|---|
| E2B template | kernel-browser — pre-built with the Kernel SDK and Playwright client |
| Public URL | sandbox.get_host(port) returns an HTTPS hostname |
| Background process | sandbox.commands.run(..., background=True) starts the web server without blocking |
| Kernel browser | kernel.browsers.create() spins up a remote Chromium; connect via kb.cdp_ws_url |
| CDP connection | Playwright’s connect_over_cdp() drives the remote browser with full API access |
Adapting this example
- Your own app — replace
FASTAPI_APPwith any web framework (Next.js, Flask, Express). Adjust the install commands and start script accordingly. - More routes — add paths to the
routeslist inBROWSE_SCRIPTto screenshot additional pages. - Visual regression — compare screenshots across deploys to catch UI regressions automatically.
- CI integration — run this as a post-deploy step to generate preview links and thumbnails for pull requests.