This guide targets Stagehand SDK v4. Stagehand v4 runs as a Chrome extension alongside the browser rather than driving it purely over CDP, so a remote Kernel browser needs the extension loaded into it (covered below). If you’re on an earlier version, see the Stagehand migration guide.
Quick start with the Stagehand template
The fastest way to run Stagehand on Kernel is our app template, which comes pre-wired for v4:index.ts— the automation (searches a startup on Y Combinator and extracts its team size).stagehand-extension.ts— a helper that loads the Stagehand extension onto the Kernel browser.
MODEL and its API key in a .env file:
.env
Adding Kernel to an existing Stagehand v4 project
If you already have a Stagehand v4 implementation, switch it to Kernel’s cloud browsers with the steps below.1. Install the Kernel SDK
zod v4 for its schema types (it pins zod@4.4.3). If your project is on zod v3, upgrade it.
2. Load the Stagehand extension onto the Kernel browser
Stagehand v4 runs as a Chrome extension. WhenlocalBrowser.connect is called without an extensionId, Stagehand loads the extension into the running browser over CDP (Extensions.loadUnpacked), reading it from a path on the browser’s filesystem. Mirror the extension — shipped inside the @browserbasehq/stagehand package — onto the running Kernel browser at that exact path first:
3. Create a browser and connect
Create a Kernel browser, load the extension, then connect Stagehand to its CDP URL:4. Use your Stagehand automation
Drive the page with Stagehand’s primitives. Note the v4 API: page access is async (activePage()), and extract returns its result under data:
5. Clean up
Stagehand v4 only closes browsers it launched, so close the connection and delete the Kernel browser yourself. Nest the cleanup so a failedclose() never skips deleting the browser:
Benefits of using Kernel with Stagehand
- No local browser management: Run automations without installing or maintaining browsers locally
- Scalability: Launch multiple browser sessions in parallel
- Stealth mode: Built-in anti-detection features for web scraping
- Session state: Maintain browser state across runs via Profiles
- Live view: Debug your automations with real-time browser viewing
Next steps
- Check out live view for debugging your automations
- Learn about stealth mode for avoiding detection
- Learn how to properly terminate browser sessions
- Learn how to deploy your Stagehand app to Kernel