https://github.com/bengabp/sandbox
Run and manage playwright in a sandbox
https://github.com/bengabp/sandbox
browser-automation docker isolated playwright python sandboxing
Last synced: about 1 month ago
JSON representation
Run and manage playwright in a sandbox
- Host: GitHub
- URL: https://github.com/bengabp/sandbox
- Owner: bengabp
- Created: 2025-03-25T19:26:37.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-26T23:10:08.000Z (about 1 year ago)
- Last Synced: 2025-03-26T23:28:38.641Z (about 1 year ago)
- Topics: browser-automation, docker, isolated, playwright, python, sandboxing
- Language: Python
- Homepage:
- Size: 105 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sandbox
[](https://git.io/typing-svg)

# :hammer_and_wrench: Building the sandbox image
The sandbox image contains code that automates playwright and wraps its dependencies together. A [base image](https://hub.docker.com/r/bengabp/sandbox) has been used which has poetry, playwright and important packages installed. This also reduces the time it takes for the sb image to build and helps you focus on sandbox code dependencies.
## Libraries in base image
- x11vnc
- xvfb
- poetry
- playwright (with system dependencies and browsers installed)
- python 3.11
- novnc
- websockify
You can extend the base image to install additional system dependencies and packages
```bash
# Building base image
docker buildx build -t docker.io//sandbox:base
# Building sb(sandbox) image
docker buildx build -t sb .
```
## Reactjs Client Connection
```typescript
// Sandbox.tsx
import React from 'react';
import { useEffect, useRef, useState } from "react";
const WS_URL = "ws://localhost:3001"; // WebSocket server running in Docker
const VNC_URL = "http://localhost:6080/vnc.html"; // noVNC server
const Sandbox: React.FC = () => {
const ws = useRef(null);
const [connected, setConnected] = useState(false);
useEffect(() => {
ws.current = new WebSocket(WS_URL);
ws.current.onopen = () => {
console.log("Connected to WebSocket server");
setConnected(true);
};
ws.current.onclose = () => {
console.log("WebSocket disconnected");
setConnected(false);
};
ws.current.onerror = (error) => {
console.error("WebSocket error:", error);
};
return () => {
ws.current?.close();
};
}, []);
return (
Remote Browser Control
Status: {connected ? "🟢 Connected" : "🔴 Disconnected"}
);
}
export default Sandbox;
```
# Api
The purpose of the api is to manage sandbox instances and dynamic code injection for new sandboxes.
## Stack
- Fastapi & Sqlalchemy - Backend & ORM
- Alembic - Database migrations
- Postgres via NeonDb - Database
## Running alembic migration
```bash
# Init alembic
alembic init alembic
# generate migration scripts
alembic revision --autogenerate -m "optional custom name"
# Apply migration
poetry run alembic upgrade head
```
## Running the api
```bash
# Install dependencies
poetry update
# Run api
uvicorn sandbox.main:app --host 0.0.0.0
```