Stagehand
Stagehand is an SDK for building browser agents, offering Playwright-style APIs with self-healing actions and token efficiency. It solves the problem of unreliable and token-heavy browser automation for AI agents, targeting developers building production-grade browser automation in TypeScript, Python, or Go.
✨ Key features
- Familiar Playwright-style APIs (goto, click, locator, screenshot).
- Self-healing actions with natural language (act, observe, extract).
- Hybrid accessibility tree trimming for token efficiency.
- Runs as a browser extension to reduce latency.
- Supports WebMCP, clipboard, batch commands, deep locators, OTel.
- Available in TypeScript, Python, and Go.
🎯 Use cases
- Automate web tasks like clicking and extracting data from pages.
- Build browser agents that adapt to website changes.
- Perform web searches and fetch page content as markdown.
- Extract structured data from web pages using schemas.
📦 Installation
🧰 Requirements: Requires Node.js (for TypeScript), an LLM API key (e.g., OpenAI), and a Browserbase API key.
To build from source:
git clone https://github.com/browserbase/stagehand.git
cd stagehand
just install
just generate
just build
Set environment variables:
export OPENAI_API_KEY="your-openai-api-key"
export BROWSERBASE_API_KEY="your-browserbase-api-key"
🚀 Usage
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 = await Stagehand.create({
browser,
model: {
modelName: "openai/gpt-5.4-mini",
apiKey: OPENAI_API_KEY,
},
});
const [page] = await browser.context.pages();
await page.goto("https://github.com/browserbase");
await stagehand.act("click on the stagehand repo");
const { data: actions } = await stagehand.observe("find the latest PR");
await page.locator(actions[0].selector).click();
const {
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"),
}),
);
❓ FAQ
What programming languages does Stagehand support?
Stagehand is available in TypeScript, Python, and Go, as it is a monorepo with packages for each language.
How does Stagehand handle website changes?
Stagehand uses self-healing primitives like act, observe, and extract that detect when sites change and automatically refresh how actions are performed.
What are the key features for agents?
Key features include WebMCP, clipboard support, self-healing actions, batch commands, deep locators for nested iframes, and OTel support.
How can I get support or contribute?
You can join the Discord community for questions or support, and contributions are welcome, especially bug fixes and small improvements.
📊 Repository
🤖 Overview, features, install steps and FAQ were generated from the project's README on Sep 4, 2026. Always check the original source before running commands.