Skip to main content
You can get started with Stagehand in just 1 minute! Choose your preferred language below.
For TypeScript/Node.js: We highly recommend using the Node.js runtime environment to run Stagehand scripts, as opposed to newer alternatives like Deno or Bun.Bun does not support Stagehand since it doesn’t support Playwright.For Python: We require Python 3.9+ and recommend using uv to manage your virtual environment.
Before you begin, you’ll need to install Node.js and NPM. We highly recommend using nvm to manage your Node.js versions, and running on Node version 20+.
1

Create a new project

You can use npx to create a new project. You should have npx included with npm, the default package manager for Node.js.
npx create-browser-app
To use our Contexts with Stagehand, run:
npx create-browser-app --example persist-context
You can easily deploy Stagehand scripts to Vercel in one line! Simply run:
npx create-browser-app --example deploy-vercel
npx vercel deploy
We also have an example using CUA agents, where we put OpenAI Operator against Anthropic’s Claude Computer Use in a heated game of chess. It’s just ten lines of Stagehand code, try it with:
npx create-browser-app --example chess
You can also use the version of Stagehand that’s on main but not released yet. This will have the bleeding edge features, but they may not be fully prod-ready yet. To test this version, try:
npx create-browser-app --alpha
It will ask you the following questions:
✔ What is the name of your project? my-app
✔ Would you like to start with a quickstart example? Yes
✔ Select AI model: Anthropic Claude 3.7 Sonnet
✔ Run locally or on Browserbase? Local
✔ Run browser in headless mode (hide Chromium popup)?  No
2

Install dependencies and run the script

cd my-app
npm install
npm run start
Use the package manager of your choice to install the dependencies. We also have a postinstall script that will automatically install the Playwright browser with playwright install.

Adding Stagehand to an existing project:

1

Install Stagehand

npm install @browserbasehq/stagehand
2

Set up environment variables

Create a .env file or export environment variables:
export BROWSERBASE_API_KEY="your_browserbase_api_key"
export BROWSERBASE_PROJECT_ID="your_browserbase_project_id"
export OPENAI_API_KEY="your_openai_api_key"  # Configurable to other models
3

Create your first script

Create a file index.ts:
// index.ts
import { Stagehand, ConstructorParams } from "@browserbasehq/stagehand";
import dotenv from "dotenv";
import { z } from "zod";

dotenv.config();

export async function main() {
  const config: ConstructorParams = {
    env: "BROWSERBASE", // or "LOCAL"
    apiKey: process.env.BROWSERBASE_API_KEY,
    projectId: process.env.BROWSERBASE_PROJECT_ID,
    verbose: 1,
  };

  const stagehand = new Stagehand(config);

  try {
    await stagehand.init();
    const page = stagehand.page;

    await page.goto("https://docs.stagehand.dev/");
    await page.act("click the quickstart link");

    const result = await page.extract({
      instruction: "extract the main heading of the page",
      schema: z.object({
        heading: z.string(),
      }),
    });

    console.log(`Extracted: ${result.heading}`);
  } catch (error) {
    console.error(error);
  } finally {
    await stagehand.close();
  }
}

main();
4

Run the script

npx tsx index.ts
Next Steps

Check out the TypeScript repo

If you’re a TypeScript developer, you can check out the Stagehand TypeScript repo. PRs welcome!

Check out the Python repo

Stagehand now supports Python! The Python repo is brand new, so PRs are more than welcome!