Skip to main content
Give your coding agent one prompt to run Chromium in a Sailbox with Playwright. The Sailbox’s egress policy applies to the browser. It sets the sites a Sailbox can reach and the secrets Sail adds to its requests. Once you’re finished, you’ll have:
  • Headless Chromium in a Sailbox, printing the title of https://example.com.
  • A sign-in where the browser types a placeholder and the site receives the password.
Share this page with your coding agent or paste the prompt below.

Manual steps

1. Build the image and create a Sailbox

You’ll need the latest Sail SDK (pip install -U sail) and a Sail API key in SAIL_API_KEY. If you’ve already run sail auth login on this machine, you can skip the key.Run this script on your machine. It prints the Sailbox ID, which later commands take as <sailbox-id>.
create_box.py
The first create builds the image, which takes about a minute. Later creates in your organization reuse it.

2. Open a page

Save this script on your machine:
browse.py
Copy it into the Sailbox and run it there:
It prints Example Domain.

3. Sign in without giving the browser the password

Save this egress policy as login.json. It sets LOGIN_PASSWORD in the Sailbox to a placeholder such as sail_ph_3kTq9..., and replaces the placeholder with the secret DEMO_PASSWORD in the password field of a form posted to httpbin.org, a test site.
login.json
Store the password as a secret in your organization, create the policy, and set it on the Sailbox:
The script types the placeholder into the form:
login.py
Output
The browser typed only the placeholder. hunter2 is in the output because httpbin sends back what it received.For your own site, name its host, the path its form posts to, and its password field in the policy. A site that signs in with a JSON request needs json in place of form, with a JSON Pointer such as "/password" as the key. The reference covers form and json.

Run Chromium with a window

A Sailbox has no screen. To give Chromium a window, add headless=False to launch and run the script under xvfb-run, which provides a virtual screen:

Watch or take over the browser

Launch Chromium with a debugging port, and keep the script running while you watch, for example with page.wait_for_timeout(600_000) before browser.close():
Start the script with sail box exec as before. In a second terminal on your machine, run sail box shell <sailbox-id>. While that shell is open, the Sailbox’s port 9222 is also on localhost:9222 on your machine, unless that port is already in use there. Open chrome://inspect in Chrome and choose inspect under the page. You see the page as it changes and can click and type in it.When you’re done, terminate the Sailbox with sail box terminate <sailbox-id>.

Gotchas

Sail answered with status 502 and didn’t send the form. The rule matched, but the placeholder was in a field it doesn’t name, or the form uploads files (multipart/form-data), which a rule can’t change.
The rule probably didn’t match, and the site received the placeholder. Check the rule’s host, method, and path.
Playwright starts Chromium without its sandbox. Chromium won’t enable it as root. Add a user to the image with .run_commands("useradd -m browser"), pass chromium_sandbox=True to launch, and run the script as that user: