Run a browser script inside the sandbox
The quickest way to start is to write a Playwright script, run it inside the sandbox, and read its output. This example opens Hacker News, reads the five top stories, and takes a screenshot of the page.1
Start a sandbox
2
Write the script
require("playwright") works without
an npm install.3
Run it and read the result
curl: the result
Output
Output
output
stories
Drive the browser from your code
Sometimes the agent runs in your own app, not in the sandbox. It then needs to control the browser remotely, one step at a time: look at the page, decide what to do, click. For that, ask the sandbox for its browser. You get back two links:Response
Response
response
cdp_url uses the Chrome DevTools Protocol (CDP), the standard way for automation tools to control Chrome. Connect
to it with Playwright from your own machine or server:
Response
Response
response
{"ttl_sec": …} (between 60 seconds and a day,
but never past the sandbox’s lifetime, if it has one). You can ask for fresh links at any time.
Watch it live
Openlive_view_url in any browser. You see the page exactly as the agent sees it, and you can click and type
into it yourself. You could show it to your user while their agent books a flight for them, or open it yourself
to find out why a script is stuck.
The live view only shows the screen and passes on clicks and key presses. It cannot run code or reach the
DevTools, so it is safe to share.
Logins that last
The browser is part of the sandbox, so when the sandbox sleeps, the browser sleeps with it, together with its open tabs, cookies, local storage and the page it was on. The next connection finds it exactly as it was. That makes “log in once, reuse for days” simple. Give each user a sandbox for the site they want automated. The user logs in once through the live view, and from then on your agent uses that logged-in session. Between uses, the sandbox sleeps: nothing for compute, and its saved state counts towards your storage.A browser from the start
If you know you will need the browser, ask for it when you create the sandbox with"needs": ["browser"]. The
browser then starts together with the sandbox, and the create answer already includes the links under browser.
Such a sandbox uses the vm runtime unless you choose another one, because browsers run faster there.
Response
Response
response
Close it
When you no longer need the browser, close it withcloseBrowser() (or DELETE /v1/sandboxes/{id}/browser). This
cancels every link, closes their connections and stops the browser. The sandbox itself keeps running.
Good to know
A few details about how the browser behaves:Clean up
Related
Desktop
A whole desktop, not only a browser, for computer-use agents.
Public URLs
Test your own app with the browser in the same sandbox.