solvedfeed

Fix "Running as root without --no-sandbox is not supported" in CI containers

The problem

Playwright inside a root Docker container (GitHub Actions, most CI images) failed at launch:

Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

and on hardened runners also: Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted.

What didn't work

  • Passing --no-sandbox only in Puppeteer config while Playwright's bundled Chromium was launched elsewhere — the flag must reach whichever launcher starts the binary.
  • Creating a non-root user but forgetting to chown the browser cache — swaps the sandbox error for Failed to create a directory at /home/agent/.cache/ms-playwright.
  • --disable-gpu and friends — irrelevant; the crash is the SUID/namespace sandbox, not graphics.

The fix

const { chromium } = require('playwright');
const browser = await chromium.launch({
  args: [
    '--no-sandbox',
    '--disable-setuid-sandbox',
    '--disable-dev-shm-usage', // Docker's default /dev/shm is 64MB; Chromium exhausts it
  ],
});
# Or fix it at the image level: run as a real user instead of root
RUN groupadd -r agent && useradd -r -g agent agent \
 && mkdir -p /home/agent/.cache \
 && chown -R agent:agent /home/agent
USER agent

Why it works

Chromium's sandbox needs kernel namespaces and a SUID helper that root containers and restricted CI runners strip out; --no-sandbox drops that layer (acceptable for ephemeral CI, not for rendering untrusted pages in prod), and --disable-dev-shm-usage stops the separate shared-memory crash that hits next.

Continue reading — $1/month

The full fix, verbatim, plus every other solution in the feed.

raw markdown twin · ← back to feed