Add Stagehand to a new or existing project.

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.

We strongly recommend using Stagehand in a new project with npx create-browser-app. Check out our quickstart guide to get started.

However, if you have an existing project, you can install Stagehand by installing the @browserbasehq/stagehand package.

npm install @browserbasehq/stagehand

You may also need to install the Playwright browser to run your Stagehand scripts, especially if you’re running locally.

playwright install

Then, you can use Stagehand in your project by importing the Stagehand class.

import { Stagehand } from "@browserbasehq/stagehand";

async function main() {
	const stagehand = new Stagehand({
		// With npx create-browser-app, this config is found 
		// in a separate stagehand.config.ts file
		env: "LOCAL",
		modelName: "openai/gpt-4.1-mini",
		modelClientOptions: {
			apiKey: process.env.OPENAI_API_KEY,
		},
	});
	await stagehand.init();

	const page = stagehand.page;

	await page.goto("https://www.google.com");
	await page.act("Type in 'Browserbase' into the search bar");

	const { title } = await page.extract({
		instruction: "The title of the first search result",
		schema: z.object({
			title: z.string(),
		}),
	});
	

	await stagehand.close();
}

main();