Guide
How to give an AI agent a headless browser
Put the browser in a sandbox, not on your machine, and connect to it over the Chrome DevTools Protocol. With Jasmine the browser is already running when the sandbox is created, so there's no launch wait.
How do I give my AI agent a browser?
Create a sandbox from a template that has headless Chromium running, get its CDP URL, and connect Playwright or Puppeteer to it.
import { chromium } from "playwright";
import { Jasmine } from "jasmine-sdk";
const sbx = await new Jasmine().create({ template: "browser" });
const browser = await chromium.connectOverCDP(await sbx.cdpUrl());
const page = await browser.newPage();
await page.goto("https://example.com");Why is the browser already running?
Because it was running when the template's snapshot was taken, and every sandbox is restored from that snapshot.
In CI, a new browser sandbox accepts CDP connections about 93 ms after it's requested. A template can do this for any server with --start and --ready-port; see browser sandboxes.
How do I connect Playwright or Puppeteer to a remote browser?
Use chromium.connectOverCDP(url) in Playwright or puppeteer.connect({ browserWSEndpoint: url }) in Puppeteer, with the WebSocket URL from sbx.cdpUrl().
Is it safe to let an agent browse the web?
Safer in a sandbox: a page that exploits the browser lands in a disposable microVM with its own kernel, not on your machine.
The sandbox can reach the internet but not your host, other sandboxes or the cloud metadata endpoint.
Can I build my own browser template?
Yes, from any image with Chromium: jasmined build browser chromedp/headless-shell:stable --mem-mib 2048 --ready-port 9222 --start '<chromium command>'. Jasmine Cloud will have it built in.
Related
- How to give Claude Code, Codex or Cursor a sandbox
- How to run AI-generated code safely
- How to mount an S3 bucket in a sandbox
- The best sandboxes for AI agents, measured
Updated 2026-11-25.
Try it in a minute
Self-host it with one command, free. Jasmine Cloud, the hosted version, is in early access.