Skip to main content
Most of the web doesn’t have an API. Browserbase gives your agents a headless browser so they can do real work on the web at scale, without breaking.
  • Browse anything — if a human can do it in a browser, your agent can too
  • Stay logged in — sessions persist across runs with contexts, no re-auth loops
  • See what your agent sees — every session is inspectable via live view and session recording
  • Access any websiteAgent Identity gets your agent past anti-bot systems and authentication walls
  • Skip the infra — no browser clusters to manage, spin up thousands of sessions on demand
Looking to deploy your browser agent? Functions let you deploy and run agents on Browserbase for faster, more secure execution — invocable via webhook or API call.

What you can build

If your agent touches the web, it needs a browser. Build agents that:
  • Navigate portals, fill out forms, and submit data on sites without APIs
  • Log into third-party tools and take action on a user’s behalf
  • Pull live data from sites that require authentication or block bots
  • Run parallel workloads across thousands of browser sessions
Whether you’re using LangChain, CrewAI, Mastra, custom tooling, or Stagehand — Browserbase drops in as the browser layer your agent already needs.

Implementation

Use Search and Fetch to gather context cheaply, then hand off to a browser agent for interaction.
1

Search the web

Use the Search API to find relevant pages without spinning up a browser. Returns structured results — quick, token-efficient recon for your agent.
2

Fetch page content

Use the Fetch API to retrieve content from a target URL. Faster and cheaper than a full session for read-only checks and pre-processing.
3

Launch a browser agent

Use Stagehand to give your agent a headless browser. The agent autonomously navigates, interacts with elements, and extracts structured data — powered by any model via the Model Gateway.

Example: Research agent

Search the web, fetch a page for recon, then launch a Stagehand agent to extract key points from the top result.
import "dotenv/config";
import { Browserbase } from "@browserbasehq/sdk";
import { Stagehand } from "@browserbasehq/stagehand";

async function main() {
  const bb = new Browserbase({ apiKey: process.env.BROWSERBASE_API_KEY! });

  const query = "best coffee shops in San Francisco";

  // Step 1: Search the web for relevant pages (no browser needed)
  const searchData = await bb.search.web({
    query,
    numResults: 5,
  });

  const topResult = searchData.results[0];
  if (!topResult) throw new Error("No search results found.");

  const targetUrl = topResult.url;

  // Step 2: Fetch page content for recon (no browser needed)
  const fetchResult = await bb.fetchAPI.create({
    url: targetUrl,
    allowRedirects: true,
  });

  console.log(`Fetched ${targetUrl}${fetchResult.content.length} chars`);

  // Step 3: Launch a browser agent with Stagehand
  // Model Gateway routes LLM requests through your Browserbase API key —
  // no separate model API key needed.
  const stagehand = new Stagehand({
    env: "BROWSERBASE",
    model: "anthropic/claude-sonnet-4-6",
  });

  await stagehand.init();

  const page = stagehand.context.pages()[0]!;
  await page.goto(targetUrl);

  const agent = stagehand.agent({
    systemPrompt:
      "You are a helpful research assistant browsing the web. " +
      "Extract factual information from pages. Be concise and structured.",
  });

  const result = await agent.execute({
    instruction:
      `You're on a page about "${topResult.title}". ` +
      `Extract the top 3 recommendations or key points from this page. ` +
      `For each, include the name and a one-sentence summary.`,
    maxSteps: 10,
  });

  console.log(result);

  // Watch the session replay to see what the agent did
  console.log(
    `Replay: https://browserbase.com/sessions/${stagehand.browserbaseSessionID}`,
  );

  await stagehand.close();
}

main().catch(console.error);
Stagehand’s Python SDK also supports this workflow. See the Python quickstart to get started.

Best practices

Use Search and Fetch for recon

Search and Fetch are faster and cheaper than a full browser session. Use them to gather context, then send your agent to pages that need interaction.
const bb = new Browserbase({ apiKey: process.env.BROWSERBASE_API_KEY! });

// Search returns structured results without a browser
const results = await bb.search.web({ query: "target query", numResults: 5 });

// Fetch retrieves page content without a browser
const page = await bb.fetchAPI.create({ url: results.results[0].url });

// Only launch a browser session for pages that need interaction

Persist sessions with contexts

Use browser contexts to save login state across agent runs. Your agent authenticates once, then picks up where it left off — no re-auth loops.
const stagehand = new Stagehand({
  env: "BROWSERBASE",
  browserbaseSessionCreateParams: {
    browserSettings: {
      context: { id: "my-agent-context", persist: true },
    },
  },
});

Constrain agent behavior with system prompts

A well-scoped system prompt reduces hallucination, limits unnecessary navigation, and keeps token usage predictable.
const agent = stagehand.agent({
  systemPrompt:
    "You are a data extraction agent. Only interact with the current page. " +
    "Do not navigate to external links. Extract structured data and return it.",
});

const result = await agent.execute({
  instruction: "Extract all pricing tiers from this page.",
  maxSteps: 5,
});

Monitor with live view and session recordings

Use live view to watch agent sessions in real time, and session recordings to debug after the fact.
const stagehand = new Stagehand({ env: "BROWSERBASE" });
await stagehand.init();

// Every session gets a replay URL automatically
console.log(
  `Watch live: https://browserbase.com/sessions/${stagehand.browserbaseSessionID}`,
);

Next steps

Stagehand

The AI SDK for browser agents

Agent Identity

Access any website without getting blocked

Contexts

Persist login state across agent runs

Functions

Deploy and run agents on Browserbase

Session live view

Watch agent sessions in real time

Model Gateway

One API key, access to every model

GitHub repository

Get started with the full ready-to-use browser agent implementation.

Browser agent demo

Clone, configure, and run in minutes