Stagehand
The SDK For Browser Agents
Last verified:
What is Stagehand?
Stagehand is an open-source AI browser automation SDK built for developers who need to reliably automate web interactions. It serves as an OSS alternative to Playwright that's easier to use and lets AI reliably read and write on the web. Stagehand gives you both the predictability of code and the adaptability of AI, making it the first browser automation framework built specifically for the AI era.
The framework provides four powerful primitives: act() for performing browser actions from plain-English instructions (click, fill, navigate, scroll), extract() for pulling structured data from any page with Zod schema validation, observe() for surfacing what's actionable on a page before committing to an action, and agent() for running multi-step workflows autonomously. Stagehand uses AI to resolve instructions like
Stagehand pricing
Pricing model: Freemium
Stagehand is fully open source and free under the MIT license. There is no paid tier for Stagehand itself. Browserbase is optional - when using Browserbase's cloud browsers for production, you need a BROWSERBASE_API_KEY. Browserbase provides headless browsers with Agent Identity, action caching, session replay, prompt observability, captcha solving, and zero-infrastructure deployment via Functions. You need to set provider API keys (like OPENAI_API_KEY) for AI models, and if using Browserbase, you can use Model Gateway to access every supported model through a single Browserbase API key.
Stagehand pros
- Open source under MIT license with active GitHub community
- Self-healing automation that survives page DOM changes
- Natural language instructions instead of brittle CSS selectors
- Four primitives: act, extract, observe, and agent for flexible automation
- Fully compatible with existing Playwright code and Page objects
- Works locally out of the box with any Chromium browser
- Zod schema validation for type-safe structured data extraction
- Supports all major AI models: OpenAI, Anthropic, Google Gemini via Vercel AI SDK
- iFrame and Shadow DOM support without additional configuration
- Server-side action caching on Browserbase reduces LLM costs
- Deterministic control - not a black-box agent
- Available in both TypeScript and Python
- Custom tools can be added for enhanced agent capabilities
- MCP integrations for connecting to external APIs and services
- Variable system keeps sensitive data like passwords away from LLMs
Stagehand cons
- Requires API keys for AI model providers (OPENAI_API_KEY, etc.)
- Browserbase integration is optional but recommended for production features
- Some advanced features like streaming and callbacks require experimental: true flag
- Computer Use Agents don't support variables, streaming, or callbacks
- Hybrid mode requires specific models that can produce accurate coordinates
- LLM-dependent so performance varies by model quality
- May have higher latency compared to pure Playwright for simple tasks
- Learning curve for developers new to AI-powered automation
Frequently asked questions about Stagehand
What is Stagehand?
Stagehand is an open source SDK that uses AI to make your browser agents resilient, readable, and production-ready. It's a browser automation framework used to control web browsers with natural language and code. Stagehand provides four primitives - act, extract, observe, and agent - that let you write browser automations using natural language instructions instead of brittle CSS selectors.
Is Stagehand open source?
Yes, Stagehand is fully open source under the MIT license. You can find the source code, contribute, and file issues on GitHub at github.com/browserbase/stagehand.
Do I need Browserbase to use Stagehand?
No, Stagehand works locally out of the box with any Chromium browser. Browserbase is optional - when you're ready for production, you can connect Stagehand to Browserbase's cloud browsers for Agent Identity, session replay, captcha solving, and zero-infrastructure deployment via Functions.
What AI models does Stagehand support?
Stagehand supports all major model providers including OpenAI, Anthropic, and Google Gemini via the Vercel AI SDK. You can specify models using the format 'provider/model' (e.g., 'openai/gpt-5', 'google/gemini-2.5-flash', 'anthropic/claude-sonnet-4-5'). If you're on Browserbase, you can also use Model Gateway to access every supported model through a single Browserbase API key.
What are the four Stagehand primitives?
The four primitives are: act() - perform browser actions from plain-English instructions like click, fill, navigate, scroll; extract() - pull structured data from any page with Zod schema validation; observe() - surface what's actionable on a page before you commit to an action; and agent() - run multi-step workflows autonomously when you need end-to-end execution.
When should I use act/extract/observe vs agent?
Use act, extract, and observe when you want precise, step-by-step control over browser actions - they're deterministic and predictable. Use agent when you need multi-step workflows executed autonomously, like navigating a complex checkout flow. Most teams combine both: agent for exploration, individual primitives for critical paths.
What browsers does Stagehand work with?
Stagehand is compatible with all Chromium-based browsers: Chrome, Edge, Arc, Brave, and more. It works locally out of the box with any Chromium browser.
How does Stagehand handle page changes?
Stagehand uses AI to resolve instructions like 'click the submit button' at runtime, not hardcoded into your test suite. This means instructions survive page redesigns because they're resolved by AI rather than relying on brittle CSS selectors that break when the DOM updates.
What programming languages does Stagehand support?
Stagehand is available in TypeScript and Python. The quickstart documentation is primarily for TypeScript, but Python support is available.
How do I get help with Stagehand?
Join the Stagehand community Discord at discord.gg/stagehand - it's the best place to ask questions, share what you're building, and get help from the team and other developers. You can also view the docs, check GitHub for issues, and see real-world automation examples at browserbase.com/templates.