Install Stagehand in your current app with the TypeScript or Python SDK.
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.

Install dependencies

npm install @browserbasehq/stagehand playwright zod
If you plan to run locally, install browsers once: npx playwright install. For cloud browser sessions, skip this.

Configure environment

Set environment variables (or a .env via your framework):
OPENAI_API_KEY=your_api_key
BROWSERBASE_API_KEY=your_api_key
BROWSERBASE_PROJECT_ID=your_project_id

Use in your codebase

Add Stagehand where you need browser automation.
import "dotenv/config";
import { Stagehand } from "@browserbasehq/stagehand";
import { z } from "zod";

async function main() {
  const stagehand = new Stagehand({
    env: "BROWSERBASE"
  });

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

  await page.goto("https://example.com");
  
  // Act on the page
  await page.act("Click the sign in button");
  
  // Extract structured data
  const { title } = await page.extract({
    instruction: "extract the page title",
    schema: z.object({
      title: z.string(),
    }),
  });

  console.log(title);
  await stagehand.close();
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});

Next steps