New:Socket for Asana Is Now Available.Learn more
Get Started

@mastra/stagehand

Package Overview
Dependencies
Maintainers
1
Versions
213
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package version was removed
This package version has been unpublished, mostly likely due to security reasons
This package has malicious versions linked to the ongoing "Mastra AI framework compromise" supply chain attack.

Affected versions:

0.2.5
View campaign page

@mastra/stagehand

AI-powered browser automation for Mastra agents using Stagehand

unpublished
Source
npmnpm
Version
0.2.5
Version published
Maintainers
1
Created
Source

@mastra/stagehand

AI-powered browser automation for Mastra agents using Stagehand.

Installation

npm install @mastra/stagehand

Usage

import { Agent } from '@mastra/core/agent';
import { StagehandBrowser } from '@mastra/stagehand';

// Create a Stagehand browser
const browser = new StagehandBrowser({
  model: 'openai/gpt-5.4',
  headless: true,
});

// Create an agent with the browser
const agent = new Agent({
  name: 'web-agent',
  instructions: 'You are a helpful web assistant.',
  model: 'openai/gpt-5.4',
  browser,
});

// Use the agent to browse the web with natural language
const result = await agent.generate('Go to google.com and search for "Mastra AI"');

Configuration

const browser = new StagehandBrowser({
  // Environment: 'LOCAL' or 'BROWSERBASE'
  env: 'LOCAL',

  // Model for AI operations (default: 'openai/gpt-5.4')
  model: 'openai/gpt-5.4',
  // Or with custom config:
  model: {
    modelName: 'gpt-5.4',
    apiKey: process.env.OPENAI_API_KEY,
  },

  // Run headless (default: true)
  headless: true,

  // Viewport dimensions
  viewport: { width: 1280, height: 720 },

  // CDP URL for connecting to existing browser
  cdpUrl: 'ws://localhost:9222',

  // Browserbase config (when env: 'BROWSERBASE')
  apiKey: process.env.BROWSERBASE_API_KEY,
  projectId: process.env.BROWSERBASE_PROJECT_ID,

  // Enable self-healing selectors (default: true)
  selfHeal: true,

  // DOM settle timeout in ms (default: 5000)
  domSettleTimeout: 5000,

  // Logging verbosity (0: silent, 1: errors, 2: verbose)
  verbose: 1,

  // Custom system prompt for AI operations
  systemPrompt: 'Focus on finding interactive elements',
});

Tools

StagehandBrowser exposes 6 AI-powered tools:

Core AI Tools

  • stagehand_act - Perform actions using natural language instructions
  • stagehand_extract - Extract structured data from pages
  • stagehand_observe - Discover actionable elements on the page

Navigation & State

  • stagehand_navigate - Navigate to a URL
  • stagehand_tabs - List, switch, open, or close browser tabs
  • stagehand_close - Close the browser

Comparison with AgentBrowser

FeatureAgentBrowserStagehandBrowser
ApproachDeterministic refs (@e1)Natural language
Token costLowHigher (LLM calls)
SpeedFastSlower
ReliabilityHigh (exact refs)Variable (AI interpretation)
Best forStructured workflowsUnknown/dynamic pages

Documentation

License

Apache-2.0

FAQs

Package last updated on 17 Jun 2026

Related posts