Skip to main content
Stagehand is an open source AI browser automation framework. It lets developers choose what to write in code vs. natural language. By integrating with Kernel, you can run Stagehand automations with cloud-hosted browsers.
This guide covers both Stagehand SDK v4 and v3. 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 — the version tabs below show each setup. To move between versions, see the Stagehand migration guide. The CLI template uses v4.

Quick start with the Stagehand template

The fastest way to run Stagehand on Kernel is our app template, which comes pre-wired for v4:
This scaffolds a self-contained app with two files:
  • 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.
Set a provider-prefixed MODEL and its API key in a .env file:
.env
Then deploy and invoke:
See the deploy and invoke guides for more.

Adding Kernel to an existing Stagehand project

If you already have a Stagehand implementation, switch it to Kernel’s cloud browsers by updating your browser setup. The steps differ between v4 and v3 — pick your version below.
1. Install the Kernel SDK
2. Load the Stagehand extension onto the Kernel browserStagehand v4 runs as a Chrome extension. When localBrowser.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 connectCreate a Kernel browser, load the extension, then connect Stagehand to its CDP URL:
4. Use your Stagehand automationDrive the page with Stagehand’s primitives. Note the v4 API: page access is async (activePage()), and extract returns its result under data:
5. Clean upStagehand v4 only closes browsers it launched, so close the connection and delete the Kernel browser yourself. Nest the cleanup so a failed close() 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