How to run Playwright on a VPS with headless Chrome
To run Playwright on a VPS with Ubuntu 24.04, install it in your project and run npx playwright install --with-deps chromium: that one command downloads Chromium and the system libraries it needs. From there your scripts run headless with no display, an AI agent can drive the browser through Playwright MCP, and on a server with a public address remote clients reach it through an SSH tunnel without opening any ports. Everything below matches the Playwright 1.65 docs, current as of Nov 20, 2026.
With the 0x.cloud MCP server connected, your agent can do the whole setup from one prompt:
Create an s4-8 server with Ubuntu 24.04 on 0x.cloud. Show the dry_run price first and wait for my "yes". Then create a sudo user named agent, add 4 GB of swap, install Node.js 26 LTS, Playwright 1.65 and Chromium with npx playwright install --with-deps chromium, verify it with a script that screenshots example.com and send me the output. Don't open any ports except SSH.
A new 0x.cloud API key gets servers.* by default, which means it can delete servers and run commands as root. This job only needs read, create and exec, so remove the rest in your dashboard and set a monthly spend limit.
Requirements and which plan to pick
| Workload | Plan | Why |
|---|---|---|
| Scheduled script, 1–2 tabs | s2-4: 2 vCPU, 4 GB, $15.99/mo (about $0.109520/h) | Chromium plus Node.js or Python fit with room to spare |
| AI agent with a browser and tools, parallel data collection | s4-8: 4 vCPU, 8 GB, $31.99/mo (about $0.219105/h) | each JavaScript-heavy tab costs hundreds of MB, and the agent runtime and tools need memory too |
| OS | Ubuntu 24.04 LTS or Debian 12 | both are officially supported by Playwright |
For an agent with a browser, go with s4-8. That's the plan we recommend on VPS for AI agents. Not sure how much you need? Use hourly billing: a full day on s4-8 is about $5.26, setup is $0, and deleting it returns the rest of your balance.
If you collect public data on a schedule, see VPS for web scraping. Respect robots.txt and each site's terms, and add delays between requests.
Prepare the server
Update packages and create a regular user. Chromium shouldn't run as root, and Playwright stores browsers in the home folder of whoever installed them.
sudo apt update && sudo apt upgrade -y
sudo adduser agent
sudo usermod -aG sudo agent
sudo ufw allow OpenSSH
sudo ufw enable
Only SSH is open. A browser needs no inbound ports.
Add swap so a memory-hungry page slows things down instead of crashing them. Full walkthrough: add swap on Ubuntu.
sudo fallocate -l 4G /swapfile && sudo chmod 600 /swapfile
sudo mkswap /swapfile && sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Install Playwright on the VPS with Node.js
Playwright 1.65 supports Node.js 22, 24 and 26. Install 26, the Active LTS line as of Nov 20, 2026, from NodeSource, then switch to the agent user:
curl -fsSL https://deb.nodesource.com/setup_26.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt install -y nodejs
su - agent
Create a project, add the library, and install the browser together with its OS dependencies:
mkdir -p ~/browser && cd ~/browser
npm init -y && npm pkg set type=module
npm install playwright@1.65.1
npx playwright install --with-deps chromium
--with-deps runs apt through sudo and pulls in fonts, libnss3, libgbm1 and the rest. The browser lands in ~/.cache/ms-playwright. For headless-only jobs, add --only-shell to download the smaller Chromium Headless Shell instead of full Chromium.
Test it with check.mjs:
import { chromium } from 'playwright';
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
console.log(await page.title());
await page.screenshot({ path: 'shot.png' });
await browser.close();
node check.mjs
You should see Example Domain and a new shot.png.
Playwright with Python on Ubuntu Server
Ubuntu 24.04 blocks global pip installs, so use a virtual environment:
sudo apt install -y python3-venv
python3 -m venv ~/pw-venv && source ~/pw-venv/bin/activate
pip install playwright==1.65.2
sudo ~/pw-venv/bin/playwright install-deps chromium
playwright install chromium
System packages go in with sudo and the full path to the venv's playwright. The browser itself installs without sudo so it ends up in the agent user's cache.
Use the official Docker image
If you'd rather not install libraries on the host, Microsoft's image ships with browsers and dependencies. Match the image tag to the Playwright version in your code:
docker run --rm --init --ipc=host \
-v "$PWD":/work -w /work \
mcr.microsoft.com/playwright:v1.65.1-noble node check.mjs
--ipc=hostmatters for Chromium: the default 64 MB/dev/shmin a container is too small and the browser crashes.--shm-size=1gbworks too.--initreaps zombie browser processes.- Without
--user, the container runs as root. That's fine for your own tests. For unknown sites, the Playwright docs recommend running aspwusertogether with a seccomp profile:--user pwuser --security-opt seccomp=seccomp_profile.json(the profile is on the Playwright in Docker page). Without it, Chromium's sandbox can't start inside the container.
The Python image is mcr.microsoft.com/playwright/python:v1.65.2-noble. Docker itself installs with one command: curl -fsSL https://get.docker.com | sudo sh. That script is fine for a test box; for production, Docker recommends installing from its apt repository.
A browser for AI agents: Playwright MCP
Agents like Claude Code drive a browser through Microsoft's Playwright MCP server. It uses the Chrome channel by default, so install Google Chrome and register the server in headless mode:
npx -y playwright install --with-deps chrome
claude mcp add playwright -- npx @playwright/mcp@latest --headless --isolated
--isolated keeps the browser profile in memory, so parallel agent sessions don't fight over one profile. To put the agent itself on the server, follow Claude Code on a server or install OpenClaw.
Remote headless Chrome without open ports
Sometimes you want the browser on the VPS and the scripts on your laptop. Playwright can run as a server, but it must listen on 127.0.0.1 only: an exposed port lets anyone drive a browser from your server's IP.
docker run -d --name pw-server --restart unless-stopped --init --ipc=host \
-p 127.0.0.1:3000:3000 --user pwuser --workdir /home/pwuser \
mcr.microsoft.com/playwright:v1.65.1-noble \
/bin/sh -c "npx -y playwright@1.65.1 run-server --port 3000 --host 0.0.0.0"
Docker bypasses ufw, so the 127.0.0.1 prefix in -p is required. Incoming connections from the internet don't reach 0x.cloud servers, so this works on a server with a public address. On your own machine, open a tunnel and connect:
ssh -N -L 3000:127.0.0.1:3000 agent@SERVER_IP
const browser = await chromium.connect('ws://127.0.0.1:3000/');
The client's Playwright version must match the server's (1.65.x).
Keep a script running with systemd
The pw-server container restarts on its own thanks to --restart unless-stopped. For a Node.js job, create /etc/systemd/system/browser-job.service:
[Unit]
Description=Playwright job
After=network-online.target
[Service]
User=agent
WorkingDirectory=/home/agent/browser
ExecStart=/usr/bin/node check.mjs
Restart=on-failure
MemoryMax=3G
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now browser-job
journalctl -u browser-job -f
User=agent matters because the browsers live in that user's cache; as root, the service won't find them. MemoryMax stops a runaway page from eating the whole server. Timers and schedules are covered in create a systemd service.
Update and back up
To update a Node.js project:
cd ~/browser
npm install playwright@latest
npx playwright install --with-deps chromium
Playwright removes old browser builds automatically. With Docker, bump the image tag and the run-server version together.
There's little to back up. Keep code in Git, and save any storageState files (cookies and logged-in sessions) plus your .env. Those files open your accounts, so keep them at mode 600. Before a big upgrade, a $0.99/mo snapshot on 0x.cloud gives you a quick way back.
Common errors
| Symptom | Cause and fix |
|---|---|
Host system is missing dependencies to run browsers |
OS libraries missing. Run sudo npx playwright install-deps chromium |
Executable doesn't exist at /home/…/ms-playwright/… |
Browser installed by another user or for another Playwright version. Run npx playwright install chromium as the service user |
Target page, context or browser has been closed under load |
Out of memory. Close contexts, cut parallel tabs, add swap or move to s4-8 |
| Chromium crashes in Docker | Missing --ipc=host or --shm-size |
Looks like you launched a headed browser without having a XServer running |
headless: false in code. Remove it or run under xvfb-run |
Version error on chromium.connect |
Client and run-server Playwright versions differ |
Official docs: Playwright in Docker and system requirements.
FAQ
How much RAM does Playwright need on a server? Headless Chromium itself takes a few hundred MB, and every tab adds more. A couple of scheduled scripts fit in 4 GB (s2-4). An AI agent that keeps a browser open while running other tools needs 8 GB (s4-8).
Do I need a desktop environment to run Playwright on Ubuntu Server? No. Playwright runs Chromium headless by default with no display. If a script must use a headed browser, wrap it in xvfb-run, which provides a virtual display.
Can I run Playwright as root? You can, but you shouldn't. Playwright launches Chromium without its sandbox by default (chromiumSandbox: false), and the sandbox can't be enabled as root anyway. That's acceptable for your own tests. For unknown sites, use a regular user or the Docker image with pwuser and the seccomp profile from the docs.
What if the plan turns out too small? Pay by the hour and switch servers without losing money: s4-8 is about $0.219105/h, the remaining balance goes back to your account when you delete a server, and OS reinstalls are $0. Support replies in about 30 minutes on average, 06:00 to 20:00 UTC. Servers are in Warsaw.