Running Chromium in Docker for an AI agent takes four settings: enough shared memory, an init process, a non-root user, and permission for the browser to build its own sandbox. Most crash reports and most uses of --no-sandbox come from missing one of these.
Why is Chromium harder to run in Docker than other programs?
Chromium is harder to run in a container because it is many processes that share memory and sandbox each other. Puppeteer's guide says plainly that "Getting headless Chrome up and running in Docker can be tricky" (Puppeteer troubleshooting, read 2026-11-24). Three container defaults get in its way:
- Small shared memory. For
--shm-size, Docker says "If you omit the size entirely, the system uses64m" (Docker run reference, read 2026-11-24). - Root by default. Chromium's sandbox is not available when the browser runs as root. Playwright's Docker page: "By default, the Docker image will use the root user to run the browsers. This will disable the Chromium sandbox which is not available with root" (Playwright Docker, read 2026-11-24).
- Restricted system calls. Docker's default system-call profile blocks creating user namespaces, which Chromium's sandbox uses on Linux.
Step 1: How do I give Chromium enough shared memory?
Give Chromium enough shared memory by sharing the host's IPC namespace or by raising the container's shared memory size.
--ipc=hostuses "the host system's IPC namespace" (docker container run, read 2026-11-24). Playwright recommends it: "Using--ipc=hostis recommended when using Chromium. Without it, Chromium can run out of memory and crash" (Playwright Docker, read 2026-11-24).--shm-size=1g(or another size) keeps a private IPC namespace with a larger /dev/shm. This keeps agent sessions on the same host more separate than--ipc=host, which matters when each container belongs to a different user.- The browser flag
--disable-dev-shm-usagemoves shared memory files out of /dev/shm. Chromium's own description: "The /dev/shm partition is too small in certain VM environments, causing Chrome to fail or crash ... Use this flag to work-around this issue (a temporary directory will always be used to create anonymous shared memory files)" (Chromium base switches, read 2026-11-24).
Newer Chromium code also reduces the dependence. A current source comment describes creating shared memory "as an anonymous memfd instead of an unlinked file in /dev/shm", which "stops depending on /dev/shm being mounted, accessible and large enough" (Chromium shared memory source, read 2026-11-24). We could not confirm which release ships this for every platform, so keep one of the settings above.
For agents, a per-container --shm-size is usually the better default, because it keeps each session's memory to itself.
Step 2: Why add --init?
Add --init so finished browser processes are cleaned up. Docker's flag will "Run an init inside the container that forwards signals and reaps processes" (docker container run, read 2026-11-24). Playwright gives the reason: "Using --init Docker flag is recommended to avoid special treatment for processes with PID=1. This is a common reason for zombie processes" (Playwright Docker, read 2026-11-24).
Step 3: How do I keep Chromium's sandbox on?
Keep Chromium's sandbox on by running the browser as a normal user and allowing it to create user namespaces.
- Create a non-root user in the image and switch to it before starting the browser. Puppeteer's example Dockerfile carries the comments "Add user so we don't need --no-sandbox." and "Run everything after as non-privileged user." (Puppeteer troubleshooting, read 2026-11-24).
- Allow user namespace creation. Playwright's documented command for crawling untrusted sites runs as its
pwuseraccount with a custom system-call profile. Playwright describes that profile as Docker's default one with extra permission to clone user namespaces, and publishes it on the same page (Playwright Docker, read 2026-11-24). You load it with Docker's--security-optoption. - Do not use
--privileged. Docker warns that it "gives all capabilities to the container" and to "Use this flag with caution" (Docker run reference, read 2026-11-24). Puppeteer's guide suggests--cap-add=SYS_ADMINonly "when developing locally".
Playwright's advice for untrusted content sums it up: "it's recommended to use a separate user for launching the browsers", together with that profile (Playwright Docker, read 2026-11-24).
On Ubuntu hosts, Puppeteer also notes that an AppArmor policy can stop downloaded test builds of Chrome from using user namespaces (Puppeteer troubleshooting, read 2026-11-24). If the browser reports "No usable sandbox!", check the host's AppArmor rules before reaching for --no-sandbox.
What does a working docker run command look like?
A working command combines the four settings. This example uses a private shared memory size, an init process and a non-root user:
docker run --rm --init \
--shm-size=1g \
--user agent \
--memory=2g --cpus=1 \
--network agent-egress \
my-agent-browser:latest
Add the --security-opt option that loads your system-call profile, in the form shown on Playwright's Docker page. The last three lines are not about Chromium. They are what turns a container into a sandbox for an agent: a memory and CPU limit so one session cannot starve the host, and a dedicated network you can restrict.
Is the official Playwright image safe for agents?
The official Playwright image is a good base, but its own documentation limits its scope. Playwright says: "This Docker image is intended to be used for testing and development purposes only" and "It is not recommended to use this Docker image to visit untrusted websites" (Playwright Docker, read 2026-11-24). It also notes that "The Playwright package/dependency is not included in the image and should be installed separately".
An AI agent visits untrusted websites by design. If you build on the image, apply the steps above: a non-root user, the namespace profile, resource limits and network rules.
What else should a browser container for an agent have?
A browser container for an agent should also have:
- One session per container. Start a container per task and delete it afterwards, so no profile or download survives.
- A writable temporary profile. A fresh user data directory in the container, never one mounted from the host.
- No host mounts beyond what the task needs, and never the Docker socket.
- Pinned versions. The browser and driver versions in the image tag, so a run can be repeated.
- Logs and traces written to a volume you collect at the end of the session, as described in our guide to recording a browser agent's session.
How do I check that the sandbox is really on?
Check the sandbox by confirming in your launch code that --no-sandbox is absent and that the browser starts without error. If Chromium cannot build its sandbox and the flag is absent, it refuses to start. Puppeteer documents the message: "If there's no good sandbox for Chrome to use, it will crash with the error No usable sandbox!" (Puppeteer troubleshooting, read 2026-11-24). A browser that starts without that flag is running sandboxed.
What we read for this article
- Puppeteer troubleshooting, read 2026-11-24
- Playwright Docker, read 2026-11-24
- Docker run reference, read 2026-11-24
- docker container run CLI reference, read 2026-11-24
- Chromium base switches (pinned copy), read 2026-11-24
- Chromium shared memory source, read 2026-11-24
Frequently asked
Why does Chromium crash in Docker?
Most often because /dev/shm is too small. Docker gives containers 64 MB of shared memory by default, and Chromium uses shared memory between its processes. Playwright's docs say that without --ipc=host Chromium can run out of memory and crash.
Should I use --no-sandbox in Docker?
Only if you fully trust every page the browser opens. Chromium documents the switch as being for testing, and Puppeteer's guide says running without a sandbox is strongly discouraged. Run as a non-root user and allow user namespaces instead.
What does --disable-dev-shm-usage do?
It tells Chromium to write its shared memory files to a temporary directory instead of /dev/shm, which avoids crashes when /dev/shm is small. Raising the shared memory size is the other fix.
Why use --init with a browser container?
Browsers start many child processes. --init runs a small init process as PID 1 that forwards signals and reaps finished processes, so zombie processes do not pile up.
Can I run a headed browser in Docker?
Yes, with a virtual display such as Xvfb inside the container. It uses more memory, so keep headless for agents that do not need a visible window.