Overview
The Playwright sandbox image includes:- Playwright Python package
- Chromium browser binaries
- Node.js and npm (for Playwright MCP integration)
- Non-root user (
playwright) for security
Building the Image
Build the Playwright sandbox image from the Dockerfile:Pull Pre-built Image
Alternatively, pull the pre-built image:Setup OpenSandbox Server
Start the local OpenSandbox server:Complete Example
This example launches Chromium in headless mode, navigates to a URL, extracts content, and captures a full-page screenshot:Example Output
The script will:- Launch Chromium in headless mode
- Navigate to the target URL (defaults to
https://example.com) - Extract the page title and body content
- Capture a full-page screenshot
- Download the screenshot to your local directory
Features
Headless Browser Automation
- Chromium runs in headless mode (no GUI required)
- Full Playwright API available for complex interactions
- Network idle detection for reliable page loading
Screenshot Capture
- Full-page screenshots supported
- Files can be downloaded from sandbox to local system
- Useful for visual verification and debugging
Content Extraction
- Extract text content from any element
- Get page metadata (title, description, etc.)
- Access rendered content after JavaScript execution
Environment Variables
| Variable | Default | Description |
|---|---|---|
SANDBOX_DOMAIN | localhost:8080 | OpenSandbox server address |
SANDBOX_API_KEY | - | API key for authentication |
SANDBOX_IMAGE | opensandbox/playwright:latest | Docker image to use |
PYTHON_VERSION | 3.11 | Python version in sandbox |
TARGET_URL | https://example.com | URL to scrape |
Use Cases
- Web Scraping: Extract data from dynamic websites
- Testing: Automate browser testing workflows
- Monitoring: Capture screenshots for change detection
- Data Collection: Gather content from multiple sources
- AI Agents: Enable AI to interact with web content
Security Benefits
- Browser runs in isolated sandbox environment
- Non-root user prevents privilege escalation
- Network isolation available through OpenSandbox
- No impact on host system if browser is compromised