Add BrowseCLI in an E2B sandbox#105
Conversation
Runs the Browserbase `browse` CLI / agent loop inside an E2B sandbox and connects out over CDP to a Verified Browserbase browser (residential IP, anti-bot fingerprint, server-side CAPTCHA solving) — the reliable way to reach the real web from a Firecracker sandbox. Complements the existing mcp-browserbase-js example. Signed-off-by: Shrey Pandya <shrey@browserbase.com>
|
We require contributors to sign our Contributor License Agreement, and we don't have @shrey150 on file. You can sign our CLA at https://e2b.dev/docs/cla . Once you've signed, post a comment here that says '@cla-bot check' |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
Signed-off-by: Shrey Pandya <shrey@browserbase.com>
Replace the scripted browse-CLI demo with a small Vercel AI SDK agent whose only tool is the browse CLI. The agent loop runs inside the E2B sandbox and drives a remote Browserbase browser over CDP; no browser runs in the sandbox. - agent.mjs: generateText agent, single browse tool, default HN task - index.ts: E2B driver uploads the agent, installs ai/@ai-sdk/anthropic/zod in the sandbox, runs node agent.mjs, streams output - e2b.Dockerfile: node:20-slim + global browse CLI (no Chrome) - env.template: add ANTHROPIC_API_KEY - remove obsolete browsecli-demo.sh and main.py Signed-off-by: Shrey Pandya <shrey@browserbase.com>
Signed-off-by: Shrey Pandya <shrey@browserbase.com>
…prompt Signed-off-by: Shrey Pandya <shrey@browserbase.com>
…otes Signed-off-by: Shrey Pandya <shrey@browserbase.com>
Flip the deep-research example to the idiomatic 'sandbox as a tool' shape: the AI SDK agent loop now runs on the host and its single bash tool execs inside the E2B sandbox via sandbox.commands.run, instead of running the loop inside the sandbox and shelling out. browse is installed in the sandbox template; BROWSERBASE_API_KEY is injected via the SDK envs option (never on disk). Adds generic deep-research prompt guidance (direct document URLs; confirm the single most recent filing) and registers the example in the root README. Removes the now-unused agent.mjs. Signed-off-by: Shrey Pandya <shrey@browserbase.com>
240997e to
13d4055
Compare
Signed-off-by: Shrey Pandya <shrey@browserbase.com>
Signed-off-by: Shrey Pandya <shrey@browserbase.com>
Signed-off-by: Shrey Pandya <shrey@browserbase.com>
…ng browse inline Signed-off-by: Shrey Pandya <shrey@browserbase.com>
…covery Update the system prompt (and README description) to have the agent learn the browse CLI by running `browse skills show` first -- the CLI's bundled usage guide -- keeping `browse --help` as a supplementary reference. `browse skills show` ships in the next browse release; the example already tracks ghcr.io/browserbase/browse :latest, so no version pin is needed. Signed-off-by: Shrey Pandya <shrey@browserbase.com>
|
Updated: the agent's system prompt now points it at |
…-local, runtime date, answer-of-record) - System prompt now states the environment fact (containerized, no local browser, sessions are remote and env-configured — never pass --local), injects today's date at runtime instead of letting the model guess, and instructs the agent to stop navigating and give its best final answer when nearing the step limit. - Bump the version-pin example in e2b.Dockerfile comment to 0.9.5. - Sync README's agent-flow description with the new prompt lines. Signed-off-by: Shrey Pandya <shrey@browserbase.com>
|
browse@0.9.5 is now released (npm + Verified against the released artifacts: rebuilt the |
Browser agent in an E2B sandbox
A deep-research agent (Vercel AI SDK) that uses an E2B sandbox as its tool surface. The agent loop runs on the host; its single
bashtool executes commands inside the sandbox viasandbox.commands.run. The sandbox image (browsecli-sandbox) has the BrowserbasebrowseCLI installed, so the agent does its research by runningbrowsecommands;browsedrives a browser that runs remotely on Browserbase over CDP — no Chrome runs in the sandbox.This is the idiomatic "sandbox as a tool" shape: the agent reasons on the host, and the sandbox is the isolated place where its commands actually run.
The default task is a product-research example: search Amazon (
https://www.amazon.com) for the current top mechanical keyboards and return a comparison of the top 5 results — each product's title, price, star rating, number of ratings, and its product URL. It is deliberately browser-only: Amazon search returns no products to a plaincurl, so the agent has to drive a real browser to get the data. The agent plans its own steps — there are no site-specific instructions in the prompt. Override the goal with theTASKenv var.What changed in this revision
browsesubcommands or flags. It tells the agent that abrowseCLI is installed and pre-configured via env vars, instructs it to learn the CLI by runningbrowse skills show(the CLI's bundled usage guide, shipped inbrowse≥ 0.9.5 — now released), withbrowse --helpas a supplementary reference, and gives one citation rule (link the document itself, not a viewer/index page).--local; (2) today's date is interpolated into the prompt at runtime (new Date().toISOString().slice(0, 10)), so the model never guesses or hardcodes a date; (3) an answer-of-record rule — if nearing the step limit, stop navigating and give the best final answer from what's been gathered.Sandbox.create(template, { envs }):BROWSERBASE_API_KEY(auth) andBROWSE_SESSION=agent. With both set, everybrowsecommand defaults to the remote Browserbase browser and shares one session — the agent never needs--remoteor--session(though it may still pass its own named session, which also works).browse/flag specifics baked into the tool).bashtool that execs inside the sandbox viasandbox.commands.run;BROWSERBASE_API_KEYonly ever lives in the sandbox env, never on disk.Files
index.tsbashtool that execs inside the sandbox.e2b.DockerfileFROM ghcr.io/browserbase/browse(the official prebuilt CLI image,node:20-slim+browse). No Chrome.e2b.tomlpackage.jsone2b,ai,@ai-sdk/anthropic,zod,tsx,dotenv).env.templateE2B_API_KEY,ANTHROPIC_API_KEY,BROWSERBASE_API_KEY.E2E Test Matrix
Run against released artifacts (
browse0.9.5, published to npm andghcr.io/browserbase/browse:latest): template rebuilt from the committede2b.Dockerfile, then the example executed exactly as written on this branch (npm installof the committedpackage.json,npm start, default Amazon task) on real E2B cloud + a live remote Browserbase browser + host modelclaude-sonnet-5.docker run --rm ghcr.io/browserbase/browse browse --version,browse skills show,browse --helpbrowse/0.9.5;skills showprints the bundled skill (frontmatter + usage guide);--helpleads with the "Start here (for AI agents): browse skills show" header.:latestnow serves 0.9.5 with the discovery surface the example's prompt depends on.e2b template create browsecli-sandbox --dockerfile e2b.Dockerfile ...(rebuild from the committed Dockerfile), then in-sandbox plumbing:browse --version,browse skills show | head -5,browse --help | head -8ghcr.io/browserbase/browse:latest; a sandbox created from it reportsbrowse/0.9.5 linux-x64,skills showprints the skill,--helpshows the agent header.npm start(full agent run, default Amazon task; host AI SDK loop → sandboxbashtool →browse→ remote Browserbase)browse skills show. Thenbrowse open "https://www.amazon.com/s?k=mechanical+keyboard" --remote --session <name>, a series ofbrowse evalextractions, and a product-page spot-check. 14/40 steps, 13 tool calls, 0 errored calls, ~120s wall-clock. Printed===== FINAL ANSWER =====with a 5-row comparison table — title, price, star rating, # of ratings, canonicalamazon.com/dp/<ASIN>URL per row — plus methodology notes (sponsored listings excluded) and the run's date (injected at runtime) cited in the header.browse skills showfirst, never passes--local, stays well under the 40-step cap, and produces a complete, correct-format answer.status=RUNNING+e2b sandbox listafter the run[]and "No sandboxes found".🤖 Generated with Claude Code