← Blog

Playwright tests on a coding agent's own machine: setup, timeouts and traces the reviewer can open

Browser tests are where an agent's loop gets slow and flaky. How to set up Playwright on the agent's own cloud machine: browsers installed in the template, one worker and a global timeout, traces kept as artifacts, and an AGENTS.md section so the agent reports failures instead of editing tests.

A coding agent that changes a web application will, sooner or later, be asked to run its browser tests. This is where the loop usually gets slow and flaky: a headless browser needs system libraries, tests compete for CPU, a hung test can block the whole run, and a failure on a machine nobody is looking at leaves nothing to look at afterwards.

This post sets up Playwright for an agent working on its own cloud machine. The Playwright details come from its continuous integration guide and browsers documentation, read on 2 December 2026. Sandscale commands are from CLI 1.4.1. We have not run your application’s tests, so every command here is the general form, and you should check it on your own template before relying on it.

Where the browsers come from

Playwright’s CI guide gives three steps for a CI machine: make sure the machine can run browsers, install the npm packages, and run the tests. For the first it offers two ways: its Docker image, or installing the dependencies with the CLI:

npm ci
npx playwright install --with-deps
npx playwright test

--with-deps also installs the operating system libraries the browsers need, which means installing system packages. That usually needs administrator rights, and it is a one-time job, so do it in the workspace template, not in the agent’s session. Ask whoever administers your templates to include the browsers and their libraries, so a new machine starts ready and the agent does not spend its first ten minutes installing system packages, or asking for permission to.

Create the machine from that template:

sandscale workspace create --name shop-4417-checkout --template-id TEMPLATE_ID --ttl-seconds 28800
sandscale workspace ssh shop-4417-checkout

The workspace disk persists, so the browsers are installed once and are still there after the machine stops and starts.

Settings that suit an unattended agent

Playwright’s CI guide has recommendations that fit an agent for the same reason they fit CI: nobody is watching.

Workers. The guide recommends setting workers to 1 in CI “to prioritize stability and reproducibility”, noting that running tests sequentially gives each test the full system resources. If you have a machine with many cores you can raise it, but start at one and measure.

A global timeout. The guide says to always set one in CI: by default a test run has no upper bound, so a suite that hangs is killed by the runner mid-run and produces no report. With globalTimeout set, Playwright stops the run and still writes the report. For an agent, the same applies: a hung test should end in a failure the agent can read, not in a session that waits until the machine’s time to live runs out.

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
  workers: process.env.CI ? 1 : undefined,
  globalTimeout: 10 * 60 * 1000,
  retries: 0,
  use: { trace: 'retain-on-failure' },
  reporter: [['list'], ['html', { open: 'never' }]],
});

Set CI=1 in the agent’s environment if you want the single-worker setting. Two choices there deserve a comment. retries: 0 is deliberate: a test that passes on a retry is a flaky test, and an agent that is told the suite passed after a retry will not mention it. And trace: 'retain-on-failure' keeps a trace for each failed test, which is what a reviewer wants to open. Check the option names against your Playwright version’s documentation before you commit this.

Running one test, not the suite

Teach the agent the narrow forms first. Both are standard Playwright options:

npx playwright test tests/checkout.spec.ts
npx playwright test tests/checkout.spec.ts -g "applies a coupon"

The first runs one file; the second one test by title. The full suite once before the pull request, as with any other test run. For a suite too heavy for the agent’s machine, run that one step on a larger leased machine; see leasing a build host for a full test suite.

Keeping the evidence

When a browser test fails on a machine that gets stopped, the trace, screenshot and report go with it. Decide where they go before the first failure:

  • The agent summarizes the failing test name and the first error in its pull request description. Not the whole log. See test results a coding agent can act on.
  • The trace or HTML report, which can be large, goes to storage a reviewer can reach. Our post on where agents should put their artifacts shows an S3-compatible bucket and a presigned link that expires on its own.
  • The reviewer opens a trace with Playwright’s trace viewer: npx playwright show-trace trace.zip. It shows the steps, the page at each step and the network calls.

The app under test

The application the tests drive has to run somewhere the browser can reach. Usually that is the same machine, started by the test config’s webServer option or by a script, on a localhost port. Then no network is needed beyond whatever your application itself calls. If your tests hit third-party services, mock them. A test that depends on an external service failing on a machine with restricted network access looks exactly like a broken test, and an agent will try to fix the test.

To look at the running application yourself from a laptop, port-forward from the workspace; our post on port forwarding a dev server shows how.

The AGENTS.md section

## Browser tests (Playwright)
- Run one spec file while working: `npx playwright test <file>`.
- Run the whole suite once before opening a PR: `npx playwright test`.
- Never edit, skip (`test.skip`), or loosen an assertion to make a test pass.
  If a test fails and you think the test is wrong, say so in the PR and leave it failing.
- Never raise timeouts or add retries to make a failure go away.
- If the browsers are missing, stop and report it. Do not install system packages.
- On failure, put the test name and the first error in the PR description and
  upload the trace as described in the Artifacts section.

Reviewers should read the diff for test files with the same suspicion as any other: a pull request that edits a failing test to pass, or adds test.skip, is the thing to look for. Our reviewer checklist has more.

Run your agents in a box of their own

Each sandbox is a Firecracker microVM. Free includes 100 awake vCPU-hours a month.

Start free

Keep reading