
Same primitives as Playwright
Claude Code, Codex and yourself already know how to write Stagehand code, thanks to its shared primitives with Playwright. Stagehand adds useful APIs for Shadow DOM, iframe support, clipboard access and more.
Stagehand is an open source SDK to build performant and resilient web automation and AI Agents. Run it locally, or on Browserbase, at the same speed.

Use familiar APIs, self-healing actions, and network-level security across TypeScript, Python, and Go.

Claude Code, Codex and yourself already know how to write Stagehand code, thanks to its shared primitives with Playwright. Stagehand adds useful APIs for Shadow DOM, iframe support, clipboard access and more.

Stagehand’s act(), observe() and extract() shorthand removes the brittleness of selectors, adapting to every web page change and enable structured data extraction.

Connecting your Stagehand program to Browserbase’s Browsers ensures performance similar to local browsers. Combining it with Browserbase’s Remote Cache and Model Gateway reduces token costs at scale.
Stagehand shares the same common primitives as Playwright, making it easy for Claude Code and Codex to generate and for you to start using.
import { z } from "zod/v4";
import { localBrowser, Stagehand } from "@browserbasehq/stagehand";
const browser = await localBrowser.launch();
const sh = await Stagehand.create({ browser });
const page = await browser.context.activePage();
if (!page) throw new Error("Stagehand initialized without an active page");
await page.goto("https://news.ycombinator.com");
const result = await sh.extract(
"Extract the top 5 stories",
z.object({
stories: z.array(
z.object({
title: z.string(),
points: z.number(),
}),
),
}),
);
console.log(result.data.stories);
await sh.close();
await browser.close();from pydantic import BaseModel
from stagehand import Stagehand, local_browser
class Story(BaseModel):
title: str
points: float
class Stories(BaseModel):
stories: list[Story]
browser = await local_browser.launch()
sh = await Stagehand.create(browser=browser)
page = await browser.context.active_page()
await page.goto("https://news.ycombinator.com")
result = await sh.extract("Extract the top 5 stories", Stories)
print(result.data.stories)
await sh.close()
await browser.close()
Stagehand consumes up to 80% fewer tokens than Playwright, with APIs optimized for Claude Code and Codex to generate.

Stagehand integrates with your favorite AI frameworks, adding web browsing capabilities to your AI workflow or AI Agent application.
Shared primitives with additional APIs for Shadow DOM, iframe support, clipboard access and more
| Feature | Stagehand | Playwright |
|---|---|---|
| Designed for | agents | testing |
| Playwright-style API | Yes | Yes |
| Faster runtime living in browser | Yes | No |
| Shadow DOM and iframe support | Yes | No |
| Domain allow-list/block-list | Yes | No |
| Built-in OTel tracing | Yes | No |
| Batching commands support | Yes | No |

Every Browserbase Browser comes with Stagehand preloaded, preventing unnecessary network roundtrips and resulting in near local browser performance.

Enable remote caching of act(), observe(), and extract() results server-side to reduce LLM costs and speed up your automations.

Combine Stagehand with Model Gateway to automatically pair the best model for each Stagehand actions, lowering inference cost by 30–40%.
Stagehand is an open-source SDK for building browser agents. It gives you three AI primitives, act(), extract(), and observe(), alongside the full Playwright-style page API, so you can mix natural language instructions with deterministic code in the same script. Stagehand is available in TypeScript, Python, and Go.
Yes. Stagehand is open source under the MIT license and free to use with any Chromium browser on your own machine. Browserbase, which creates and maintains Stagehand, is a separate paid product for running browser agents in production. You never need a Browserbase account to use Stagehand.
Playwright was built for testing, Stagehand is built for agents. Playwright depends on hardcoded selectors that break when a site changes its DOM, while Stagehand resolves instructions like "click the submit button" at runtime and self-heals. Stagehand keeps the Playwright API surface, so goto(), click(), and locator() work exactly as you expect.
Yes. Stagehand runs locally out of the box against any Chromium browser, and the full SDK is available without an account. Connecting to Browserbase adds hosted browsers, session replay, server-side caching, the Model Gateway, and Verified access, which is what most teams move to when they go to production.
Stagehand ships first-class SDKs for TypeScript, Python, and Go, with feature parity across all three. v4 achieves parity by moving the shared core into the browser runtime instead of reimplementing it per language, so a feature that lands in one SDK lands in all three.
Stagehand is model-agnostic. You can name a supported provider directly or supply your own client-side LLM callback, which means you can run Claude, GPT, Gemini, or a local model without changing your automation code. On Browserbase, the Model Gateway routes every model through one API key.
Stagehand v4 moves the runtime into the browser itself, so state, target management, and CDP dispatch live alongside the page instead of in your client. That change delivers roughly 2x faster wall-clock time on a 50-action crawl, uniform handling of cross-origin and nested iframes, shadow DOM support including closed roots, real clipboard access, WebMCP, and domain policy enforced before requests leave the browser.
v4 introduces breaking changes, so v3 scripts need updating. The main ones: construction moves to Stagehand.create({ browser }), act(), extract(), and observe() move from the page to the Stagehand instance, all calls now return { data, metadata }, agent() is removed in favour of code mode or tool calling, and deepLocator() folds into locator(). The migration guide covers each change with before and after code.
Stagehand is designed to survive DOM changes that break traditional scripts. Because act() and observe() resolve intent at runtime rather than matching a stored CSS selector, a redesigned page usually keeps working without code changes. For steps where you need guaranteed behavior, you can drop to deterministic Playwright-style selectors in the same script.
Stagehand itself is free and open source. Your cost is the LLM inference for act(), extract(), and observe() calls, which you control by choosing your own model. Running on Browserbase adds server-side caching that replays resolved actions instead of re-inferring them, cutting cost on repeated runs.
You can, but it is not what v4 optimizes for. Stagehand is built for agents that operate on live production websites they do not control, where the DOM changes without warning. If your target is your own app in CI with a stable DOM, Playwright remains the better fit.