Stagehand allows you to build web automations with natural language and code.
If this is your first time using Stagehand, you should try Director first. It’s an agent that allows you to build Stagehand workflows using natural language. You can also try Stagehand using our MCP server .Otherwise, the quickest way to start with Stagehand is with our CLI. It scaffolds a ready‑to‑run Stagehand app with sensible defaults, and an example script.
This quickstart is for TypeScript. For Python, see the installation guide.
The scaffold includes an index.ts file that contains the example script. Here’s what it looks like:
Copy
Ask AI
import "dotenv/config";import { Stagehand } from "@browserbasehq/stagehand";async function main() { const stagehand = new Stagehand({ env: "BROWSERBASE" }); await stagehand.init(); console.log(`Stagehand Session Started`); console.log(`Watch live: https://browserbase.com/sessions/${stagehand.browserbaseSessionID}`); const page = stagehand.page; await page.goto("https://stagehand.dev"); const extractResult = await page.extract("Extract the value proposition from the page."); console.log(`Extract result:\n`, extractResult); const actResult = await page.act("Click the 'Evals' button."); console.log(`Act result:\n`, actResult); const observeResult = await page.observe("What can I click on this page?"); console.log(`Observe result:\n`, observeResult); const agent = await stagehand.agent({ instructions: "You're a helpful assistant that can control a web browser.", }); const agentResult = await agent.execute("What is the most accurate model to use in Stagehand?"); console.log(`Agent result:\n`, agentResult); await stagehand.close();}main().catch((err) => { console.error(err); process.exit(1);});
To use, set provider keys in .env (e.g., OPENAI_API_KEY). For cloud browsers, add BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID.