Skip to main content

BrowserEnv

Unified browser automation environment supporting both DOM-based (natural language) and CUA-based (vision + coordinates) control.

Overview

BrowserEnv provides two distinct browser automation modes:
  • DOM mode: Natural language operations via Stagehand SDK (act, observe, extract, navigate)
  • CUA mode: Vision-based primitives (click, scroll, type_text, screenshot)
Both modes integrate with Browserbase for cloud browser management and support local execution.

Installation

Install with browser support:
Or when developing in the verifiers repo:
See Browser Examples for complete setup and usage.

Inheritance

Constructor

Parameters

Mode Selection

Literal['dom', 'cua']
default:"dom"
Operating mode:
  • "dom": Natural language browser control via Stagehand SDK
  • "cua": Vision-based control using coordinate primitives

Shared Configuration

str | None
default:"None"
Browserbase project ID. Required when using Browserbase.
str
default:"BROWSERBASE_API_KEY"
Environment variable name for Browserbase API key.

DOM Mode Parameters

str
default:"MODEL_API_KEY"
Environment variable name for model API key (OpenAI, Anthropic, etc.).
str
default:"openai/gpt-4o-mini"
Model used by Stagehand for DOM understanding and action planning.
bool
default:"False"
Whether to proxy model API calls through Stagehand.

CUA Mode Parameters

bool
default:"True"
Auto-deploy CUA server to sandbox. If False, connects to server_url.
str
default:"http://localhost:3000"
CUA server URL when use_sandbox=False.
Literal['LOCAL', 'BROWSERBASE']
default:"BROWSERBASE"
Browser execution environment:
  • "BROWSERBASE": Cloud browsers via Browserbase
  • "LOCAL": Local browser execution
int
default:"1024"
Browser viewport width in pixels.
int
default:"768"
Browser viewport height in pixels.
bool
default:"True"
Save screenshots to disk during execution.
int | None
default:"2"
Number of recent screenshots to keep in message context. Set to None to keep all.
bool
default:"False"
Enable Browserbase proxies for IP rotation.
bool
default:"False"
Enable Browserbase Advanced Stealth mode for anti-bot detection.

CUA Sandbox Configuration

int
default:"3000"
Port for CUA server in sandbox.
int
default:"120"
Timeout in seconds waiting for sandbox server to be ready.
float
default:"2.0"
Poll interval in seconds for sandbox server health checks.
str
default:"node:18-slim"
Docker image for sandbox (only used when use_prebuilt_image=False).
int
default:"2"
CPU cores allocated to sandbox.
int
default:"4"
Memory in GB allocated to sandbox.
int
default:"10"
Disk size in GB for sandbox.
int
default:"60"
Sandbox timeout in minutes.
int
default:"60"
Per-command timeout in sandbox.
bool
default:"True"
Use pre-built SEA binary when use_prebuilt_image=False. If False, installs from npm.

Pre-built Image Configuration

bool
default:"True"
Use pre-built Docker image for fastest startup. Recommended for production.
str
default:"deepdream19/cua-server:latest"
Docker image to use when use_prebuilt_image=True.

Error Handling

list[type[Exception]] | None
default:"None"
Exception types that should trigger cleanup. Defaults to [vf.SandboxError].
Any
Additional arguments passed to StatefulToolEnv.

DOM Mode Tools

Navigate to a URL.

act

Perform an action described in natural language (e.g., “click the login button”, “fill in the email field with test@example.com”).

observe

Find elements or information matching the instruction (e.g., “find all product cards”, “locate the search bar”).

extract

Extract structured data from the page according to a JSON schema.

CUA Mode Tools

click

Click at coordinates (x, y).

type_text

Type text at the current cursor position.

scroll

Scroll the page. Direction can be “up” or “down”.

screenshot

Capture a screenshot of the current page. Returns path to screenshot file.

Key Methods

setup_state

Initialize browser session for this rollout. Delegates to mode-specific implementation (DOM or CUA).

update_tool_args

Inject session state into tool calls. Delegates to mode-specific implementation.

get_prompt_messages

Get prompt messages. In CUA mode, filters screenshots to keep only recent ones based on keep_recent_screenshots.

cleanup_session

Clean up browser session after rollout.

teardown

Clean up environment resources (e.g., sandbox servers in CUA mode).

Example Usage

DOM Mode

CUA Mode with Sandbox (Default)

CUA Mode with Local Server

CUA Mode Execution Options

CUA mode supports three execution strategies (from fastest to most flexible):
  • Fastest startup (no binary upload or npm install)
  • Uses pre-built deepdream19/cua-server:latest image
  • Best for production and rapid iteration

2. Binary Upload

  • Builds/uploads SEA binary to sandbox
  • Useful for custom server versions
  • Slower startup than pre-built image

3. Local Server

  • Connect to manually started CUA server
  • Useful for local development and debugging
  • Requires running npm start in assets/templates/browserbase/cua/

Screenshot Management (CUA Mode)

CUA mode automatically manages screenshots in the message history:
  • save_screenshots=True: Screenshots saved to disk
  • keep_recent_screenshots=2: Only 2 most recent screenshots kept in context
  • Older screenshots filtered out via get_prompt_messages() to reduce token usage

See Also