Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions solutions/browsecli-vercel-sandbox/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# --- Browserbase (the cloud browser the agent drives) ---
# Get a key at https://www.browserbase.com/settings
BROWSERBASE_API_KEY=bb_live_xxxxxxxxxxxxxxxxxxxxxxxx

# --- Vercel Sandbox auth (to create the Firecracker microVM) ---
# Token: https://vercel.com/account/tokens
# Team + Project IDs: Vercel dashboard → Project → Settings
VERCEL_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxx
VERCEL_TEAM_ID=team_xxxxxxxxxxxxxxxxxxxxxxxx
VERCEL_PROJECT_ID=prj_xxxxxxxxxxxxxxxxxxxxxxxx

# --- Model auth: Vercel AI Gateway (no separate Anthropic key needed) ---
# The agent's model (anthropic/claude-sonnet-5) is served through Vercel AI
# Gateway, so one Vercel auth covers both the Sandbox and the model. Pick ONE:
#
# 1. OIDC (recommended, keyless): run `vercel link` then `vercel env pull
# .env.local` in this directory. Vercel writes a short-lived
# VERCEL_OIDC_TOKEN to .env.local that the Gateway reads automatically — no
# extra key to manage. (Refresh it with `vercel env pull` when it expires.)
#
# 2. AI Gateway API key: create one at https://vercel.com/dashboard/ai-gateway
# and set it here. Use this if you prefer a long-lived key over OIDC.
# AI_GATEWAY_API_KEY=vck_xxxxxxxxxxxxxxxxxxxxxxxx

# --- Optional: override the agent's task ---
# TASK=Find the latest Node.js LTS version and its release date from nodejs.org.
37 changes: 37 additions & 0 deletions solutions/browsecli-vercel-sandbox/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# Dependencies
/node_modules
/.pnp
.pnp.js

# Next.js
/.next/
/out/
next-env.d.ts

# Production
build
dist

# Misc
.DS_Store
*.pem

# Debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Local ENV files
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# Vercel
.vercel

# typescript
*.tsbuildinfo
50 changes: 50 additions & 0 deletions solutions/browsecli-vercel-sandbox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Browser agent with bash-tool in a Vercel Sandbox

A [Vercel AI SDK](https://ai-sdk.dev) agent that uses Vercel's [`bash-tool`](https://github.com/vercel-labs/bash-tool) to run the [`browse`](https://www.npmjs.com/package/browse) CLI inside a [Vercel Sandbox](https://vercel.com/docs/vercel-sandbox) — an ephemeral Firecracker microVM. The `browse` CLI drives a real browser running on [Browserbase](https://www.browserbase.com), so the browser itself never runs in the microVM.

## How it works

```
┌──────────────────────────────┐ ┌──────────────────────────────┐ CDP/wss ┌────────────────────────────┐
│ Host (your machine / CI) │ │ Vercel Sandbox (microVM) │ ──────────▶ │ Browserbase cloud browser │
│ │ │ node24 │ │ │
│ ToolLoopAgent (AI SDK) │ ─bash─▶ │ browse CLI runs here │ ◀──────────── │ navigates / reads pages │
│ reasoning + tool loop │ │ (installed by sandbox.ts) │ page data │ │
└──────────────────────────────┘ └──────────────────────────────┘ └────────────────────────────┘
```

- The **agent loop runs on the host**. `sandbox.ts` provisions the sandbox, installs the `browse` CLI inside it, builds a `bash` tool with `bash-tool` (`createBashTool({ sandbox })`), and runs a `ToolLoopAgent`.
- The **model is served through [Vercel AI Gateway](https://vercel.com/docs/ai-gateway)**. A bare `provider/model` string (`anthropic/claude-sonnet-5`) resolves through the default Gateway provider in `ai@6`, authenticated by Vercel's OIDC token — so the same Vercel auth that powers the Sandbox also powers the model, and no `ANTHROPIC_API_KEY` is needed.
- Only the **`bash` tool executes inside the sandbox**. The model navigates the web by emitting `browse` commands, which `bash-tool` runs in the microVM.

The default task is a product-research example: on Amazon, search for the current top mechanical keyboards and, for the top 5 results, compare each product's title, price, star rating, and number of ratings — returning a comparison table with each product's URL. It is a genuinely browser-only task: Amazon search renders its results client-side and returns nothing useful to a plain HTTP fetch, so the agent has to drive a real browser. The agent plans its own steps — there are no site-specific instructions in the prompt. Override the goal with the `TASK` env var.

## Setup

The agent's model (`anthropic/claude-sonnet-5`) is served through [Vercel AI Gateway](https://vercel.com/docs/ai-gateway), so **one Vercel auth covers both the Sandbox and the model — there is no separate `ANTHROPIC_API_KEY`.**

You need:

- `BROWSERBASE_API_KEY` — the cloud browser ([browserbase.com/settings](https://www.browserbase.com/settings)). It is passed to the sandbox as a default environment variable (stored encrypted by Vercel and injected into the `browse` commands), so it is never written to a file in the sandbox.
- Vercel Sandbox credentials — `VERCEL_TOKEN` ([vercel.com/account/tokens](https://vercel.com/account/tokens)), `VERCEL_TEAM_ID`, and `VERCEL_PROJECT_ID` (from your Vercel project settings).
- Model auth via AI Gateway — pick one:
- **OIDC (recommended, keyless):** link this directory to a Vercel project and pull its env. The `vercel` CLI writes a short-lived `VERCEL_OIDC_TOKEN` that the Gateway reads automatically — nothing else to manage:
```bash
vercel link # link to your Vercel project
vercel env pull .env.local # writes VERCEL_OIDC_TOKEN
```
- **AI Gateway API key:** create one at [vercel.com/dashboard/ai-gateway](https://vercel.com/dashboard/ai-gateway) and set `AI_GATEWAY_API_KEY` in `.env`. Use this if you prefer a long-lived key over OIDC.

```bash
pnpm install
cp .env.example .env # fill in BROWSERBASE_API_KEY + Vercel Sandbox creds
vercel link # OIDC path: link the project…
vercel env pull .env.local # …and pull VERCEL_OIDC_TOKEN (skip if using AI_GATEWAY_API_KEY)
pnpm start
```

> AI Gateway requires the Vercel team to have a payment method / billing enabled to service model requests (free credits unlock once a card is on file). This is the only model-side prerequisite — there is no Anthropic account or key.

A successful run provisions a sandbox, prints each `browse` command the agent issues through the `bash` tool, and ends with a `===== FINAL ANSWER =====` summary.

The default uses a plain `--remote` Browserbase session, which works on any plan. Verified browsers (residential IP + automatic CAPTCHA solving) are a Scale-plan upgrade — see [browserbase.com/pricing](https://www.browserbase.com/pricing).
24 changes: 24 additions & 0 deletions solutions/browsecli-vercel-sandbox/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "browsecli-vercel-sandbox",
"version": "1.0.0",
"private": true,
"license": "MIT",
"repository": "https://github.com/vercel/examples.git",
"description": "A bash-tool agent that runs the browse CLI inside a Vercel Sandbox, driving a Browserbase cloud browser.",
"type": "module",
"scripts": {
"start": "tsx sandbox.ts",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@vercel/sandbox": "^2.2.1",
"ai": "^6.0.0",
"bash-tool": "^1.3.0",
"just-bash": "^3.0.1"
},
"devDependencies": {
"@types/node": "^20.14.0",
"tsx": "^4.19.0",
"typescript": "^5.5.0"
}
}
Loading