Skip to main content
This example gives an agent one narrow browser tool. Playwright launches its bundled Chromium browser inside a fresh Harnest container, reads an approved page, and returns its title and visible text.
The model cannot submit arbitrary Python or choose another sandbox. The authored tool validates the URL and creates the browser code.

Requirements

Install Harnest by following Install if harnest --version is unavailable.
You do not need to install Python or Playwright locally. harnest env sync creates the isolated agent environment and installs Harnest’s managed framework runtime. The Dockerfile installs Playwright and Chromium in the sandbox image, so the agent’s pyproject.toml needs no browser dependency.

Create the browser image

Add a pinned Playwright build context. The underscore keeps the image directory out of sandbox discovery while Harnest still includes it in the compiled source artifact. Build it before serving the agent:
sandbox/_chrome_image/Dockerfile
The Playwright package and image must use the same version so the package can find its browser executable.

Declare the sandbox

Create sandbox/chrome.py. Browser navigation needs network access, so this sandbox opts in with network=True and uses larger memory, process, and scratch budgets than the calculation example.
sandbox/chrome.py
Harnest uses the local image only when the sandbox first executes. It runs Chromium as a non-root user with a read-only root filesystem, dropped capabilities, bounded writable scratch space, and a fresh container per call.

Add the browser tool

Create tools/browse_page.py. Keep the allowlist narrow. This example allows only example.com and playwright.dev, and applies the same policy to redirects and subresources inside the browser.
tools/browse_page.py
The tool serializes the URL as JSON data before adding it to the submitted program. It limits visible text to 4,000 characters and returns no browser logs or provider details to the model.

Assign the sandbox

Add chrome to the agent’s sandbox grants:
agent.py
Tell the agent when and how to use the tool:
instructions.md

Run the example

1

Verify Harnest

2

Start Docker

Check that the daemon is available:
3

Set the model credential

Export the key in the same shell that will run the server:
Keep secrets out of config.yaml, source files, and the browser image. The example’s checked-in configuration already sets OPENAI_MODEL and OPENAI_BASE_URL.
4

Build the browser image

From the agent project directory, run:
The Playwright image is large, so its first build can take a few minutes.
5

Create and test the agent environment

env sync creates the isolated environment and resolves the managed ADK version. test validates the project without starting the browser container.
6

Serve the agent

Open http://127.0.0.1:8080/ and ask: “Read https://example.com and tell me what it is for.”
For deployment, publish the image to your registry and change image to its immutable registry reference.
network=True gives the container outbound network access. The tool’s exact-host allowlist is therefore part of its security boundary. Review redirects, resource hosts, credentials, downloads, and returned content before expanding it. Harnest’s Docker container is the process isolation boundary in this example; Chromium’s own namespace sandbox is disabled. Docker shares the host kernel, so use a stronger browser isolation provider for hostile sites or higher-risk workloads.
See Sandboxing for scope, resource, cleanup, custom provider, and framework behavior.