# Stagehand

> Control the browser with natural language and code in one TypeScript SDK

- Category: Agents & Automation / Computer & Browser Use
- Language: TypeScript
- Licence: MIT
- Repository: https://github.com/browserbase/stagehand
- Website: https://stagehand.dev
- Canonical page: https://ai-tldr.dev/tools/stagehand/

## In short

Stagehand is a TypeScript browser automation framework from Browserbase. It sits in the Computer & Browser Use category of the Agents & Automation tools and is open-source, written in TypeScript and licensed MIT. To get started: scaffold a new project.

## Overview

Stagehand is a TypeScript browser automation framework from Browserbase. It lets you drive a real web browser using a mix of natural language and normal code, so you can describe an action in plain English when you don't know a page's structure and fall back to precise code when you do.

It is aimed at developers who find low-level tools like Selenium, Playwright, or Puppeteer too verbose for unfamiliar pages, but who also find fully autonomous agents too unpredictable for production. Stagehand sits between the two: you choose, action by action, whether AI or code is in control.

As an agent framework for browser use, it adds act(), extract(), and agent() methods on top of a CDP browser engine. It also caches repeatable actions and self-heals when a site changes, so workflows can run without calling an LLM every time.

## What it does

- act() runs a single action described in natural language, such as clicking a specific link
- extract() pulls structured data from a page using a Zod schema you define
- agent() executes multi-step tasks autonomously, like navigating to the latest pull request
- Auto-caching replays previously learned actions without LLM inference to save time and tokens
- Self-healing re-involves the AI only when a website changes and a cached action breaks
- Built on a CDP browser engine and works with an LLM provider key plus Browserbase credentials

## Getting started

The fastest way to start is the project scaffolder, which sets up a working browser-automation app for you.

1. Scaffold a new project

   Run the create command to generate a starter Stagehand app.

```bash
npx create-browser-app
```

2. Add your API keys

   Stagehand works best with an LLM provider API key and Browserbase credentials. Copy the example env file and fill in your keys.

```bash
cp .env.example .env
nano .env # add your API keys
```

3. Drive the browser

   Use act() for single actions, agent() for multi-step tasks, and extract() with a Zod schema for structured data.

```ts
const page = stagehand.context.pages()[0];
await page.goto("https://github.com/browserbase");

// Single action
await stagehand.act("click on the stagehand repo");

// Multi-step task
const agent = stagehand.agent();
await agent.execute("Get to the latest PR");

// Structured extraction
const { 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"),
  }),
);
```

## When to use it

- Automating web tasks on unfamiliar pages where you can't write selectors in advance
- Extracting structured data from web pages into typed objects with a Zod schema
- Turning AI-driven exploration into repeatable, cached workflows that run without an LLM
- Building production web agents that mix natural-language steps with precise code
