What you’re integrating
Anchor SDK in a Modal image → Anchor Cloud. The Sandbox stays small. Chromium runs as a managed Anchor cloud session; the Sandbox holds the SDK and talks to it over HTTPS and CDP.- Modal stays the code runtime: install packages, run a script, call a model.
- Anchor stays the remote browser: stealth, proxies, live view and session lifecycle.
- Do not launch a browser inside the Sandbox.
Before you start
Install Modal and log in.modal setup writes a token that both the Python and JavaScript SDKs read.
ANCHORBROWSER_API_KEY. The Python SDK reads it on its own, and the TypeScript samples pass it to the SDK.
Build the image once
Modal recommends a named image for Sandboxes, so a Sandbox never waits on an image build when it starts. Build and publish one that holds the Anchor SDK and the Playwright client:await, so set "type": "module" in your package.json.
The same build in Modal’s Logs tab:

playwright (Python) and playwright-core (Node.js) are only the client library that speaks CDP. You do not run playwright install, because the browser lives on Anchor. That is why the build takes seconds.
Run a web task from the Sandbox
Describe the goal in plain English and let Anchor’s agent drive the browser. The script below starts a Sandbox from the named image, attaches the Secret, runs the task and terminates the Sandbox.python or tsx, not modal run. A Sandbox created from outside Modal only needs an App to belong to, which modal.App.lookup and modal.apps.fromName provide.
In the TypeScript version the Sandbox starts in /app, the directory where the image installed the packages, so node can resolve anchorbrowser.
Each run shows up under the App’s Sandboxes tab in Modal:

A web task starts a browser session and leaves it running when the task finishes. End it as the scripts do, with
delete_session(result.data.sessionId) in Python or Sessions.deleteSession in TypeScript, or it stays open until Anchor’s idle timeout.Drive the browser yourself with Playwright
For step-by-step control, create an Anchor session and connect Playwright to it over CDP from inside the Sandbox.Watch the browser
Open thelive view URL in your own browser while the script runs, or open the session in the Anchor dashboard. You see the live browser next to the session details and the task run:

Lock the Sandbox to Anchor
By default a Modal Sandbox can reach any public address. When the code inside is untrusted, limit it to the two hosts the Anchor SDK needs with a Modal Outbound Policy:live.anchorbrowser.io is opened by the person watching, not by the Sandbox, so it does not need to be on the list.
Clean up two lifecycles
There are two things to end, and ending one does not end the other.- The Anchor session. End it in a
finallyblock. Terminating the Sandbox stops the Sandbox only; the cloud browser keeps running and billing until its own timeout. - The Modal Sandbox. Call
sb.terminate()in afinallyblock. A Sandbox lives for 5 minutes by default; passtimeout(seconds, Python) ortimeoutMs(milliseconds, TypeScript) when you create it for up to 24 hours. - Set Anchor’s
timeout.max_durationandtimeout.idle_timeout, in minutes, as a safety net for a Sandbox that dies mid-run. See Session Timeout. - Reuse one Anchor session for a whole agent run instead of creating one per page.
API key
Each customer brings their own Anchor key as a Modal Secret namedanchorbrowser. Anchor bills them directly for browser usage; Modal bills for the Sandbox.
Troubleshooting
401from Anchor inside the Sandbox: the Secret is missing or the variable has a different name. Runmodal secret listand check the Secret holdsANCHORBROWSER_API_KEY.- The Sandbox waits a long time to start: it is building the image inline. Build and publish the named image first, then load it by name.
getaddrinfo ENOTFOUND connect.anchorbrowser.ioafter adding an Outbound Policy: onlyapi.anchorbrowser.iois on the list. The session is created, but Playwright cannot open the CDP websocket. Addconnect.anchorbrowser.io.ERR_REQUIRE_ASYNC_MODULEwhen running a.tsscript: the project is not an ES module. Set"type": "module"inpackage.json.- The Sandbox exits before the task finishes: raise the timeout on the Sandbox and on
sb.exec. A web task can take a few minutes.

