Stagehand is the SDK for browser agents. Read the Docs
What is Stagehand?
Stagehand is the SDK for browser agents. Playwright was built for testing, Stagehand is built for agents. Use familiar APIs, self-healing actions, and network-level security across TypeScript, Python, and Go.
Why Stagehand?
Stagehand gives browser agents an interface built for how they actually work. It combines familiar Playwright-style APIs with self-healing actions, agent-optimized page context, and native support for complex DOM structures like out-of-process iframes and closed Shadow DOMs.
Agents use fewer tokens, recover when websites change, and complete tasks more reliably. With a complete browser driver across TypeScript, Python, and Go, Stagehand delivers the flexibility of AI without sacrificing the speed, control, determinism, reliability, and observability required in production.
1. Familiar APIs
The Playwright-style methods you and your agents already know and love (goto, click, locator, screenshot).
2. Token efficiency as a priority
Stagehand's hybrid accessibility tree trimming gives your agents exactly what they need to understand the page and nothing more.
3. Faster in production
Stagehand runs as an extension next to the browser, closing the distance and reducing round-trip latency for all actions on the page.
4. Self-healing primitives
Use act, observe, and extract with natural language to automate pages. When sites change, Stagehand detects it and refreshes how the actions happen on the page automatically.
5. Features agents need
WebMCP, clipboard support, self-healing actions, batch commands, deep locators for nested iframes, and OTel support.
Here's how to build a sample browser automation with Stagehand:
import { browserbase, Stagehand } from"@browserbasehq/stagehand";
import { z } from"zod/v4";
const { BROWSERBASE_API_KEY, OPENAI_API_KEY } = process.env;
const browser = await browserbase.launch({
apiKey: BROWSERBASE_API_KEY,
});
const stagehand = awaitStagehand.create({
browser,
model: {
modelName: "openai/gpt-5.4-mini",
apiKey: OPENAI_API_KEY,
},
});
// Stagehand's CDP engine provides an optimized, low level interface to the browser built for automationconst [page] = await browser.context.pages();
await page.goto("https://github.com/browserbase");
// Use act() to execute individual actionsawait stagehand.act("click on the stagehand repo");
// Use observe() to see what's actionable on the pageconst { data: actions } = await stagehand.observe("find the latest PR");
// Use locators for deterministic Playwright-style actionsawait page.locator(actions[0].selector).click();
// Use extract() to get structured data from the pageconst {
data: { author, title },
} = await stagehand.extract(
"extract the author and title of the PR",
z.object({
author: z.string().describe("The username of the PR author"),
title: z.string().describe("The title of the PR"),
}),
);
See the Python and Go READMEs for equivalent examples.
The same browserbase facade also exposes Browserbase Search and Fetch without launching a browser:
just example act # runs packages/sdk-ts/examples/act.ts
See CONTRIBUTING.md for the full TypeScript, Python, and Go setup.
Contributing
[!NOTE]
We highly value contributions to Stagehand! For questions or support, please join our Discord community.
We're focused on improving reliability, extensibility, speed, and cost in that order of priority. If you're interested in contributing, bug fixes and small improvements are the best way to get started. For more involved features, we strongly recommend reaching out to Miguel Gonzalez or Paul Klein in our Discord community before starting to ensure that your contribution aligns with our goals.
Acknowledgements
We'd like to thank the following people for their major contributions to Stagehand:
A browser automation library with APIs for Chromium, Firefox, and WebKit. It offers precise, code-driven selectors and interactions; Stagehand adds AI-assisted natural-language actions and extraction on top of a Playwright-style workflow.
A browser automation library commonly used to control Chrome or Chromium through code. It is a strong choice for explicit scripting and browser tasks, while Stagehand focuses more on using AI to interpret page content and instructions.
Playwright's test runner, with fixtures, assertions, and tools for browser end-to-end tests. It is geared toward repeatable, explicitly specified tests; Stagehand is more focused on AI-assisted browser automation and extracting information from pages.
A Puppeteer extension framework that supports plugins for customizing browser automation. It builds on Puppeteer's code-driven model, whereas Stagehand's distinguishing approach is AI-assisted interaction with page content.
The npm package @browserbasehq/stagehand receives a total of 0 weekly downloads. As such, @browserbasehq/stagehand popularity was classified as not popular.
We found that @browserbasehq/stagehand demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 8 open source maintainers collaborating on the project.
Cursor removed a malicious Claude Code 2.1.313 extension from its marketplace. Socket examines registry records and the initial claims about its distribution.