Spaces:
Sleeping
Sleeping
Commit Β·
af0024b
1
Parent(s): 6652512
Auto-commit: README.md updated
Browse files
README.md
CHANGED
|
@@ -1,158 +1,313 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
| 10 |
|
| 11 |
sdk: dockersdk: docker
|
| 12 |
|
|
|
|
|
|
|
| 13 |
pinned: truepinned: false
|
| 14 |
|
|
|
|
|
|
|
| 15 |
license: mitlicense: mit
|
| 16 |
|
|
|
|
|
|
|
| 17 |
------
|
| 18 |
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
-
# π Landrun Sandbox + Browser Automation# π³ Docker Sandbox Executor
|
| 22 |
|
|
|
|
| 23 |
|
|
|
|
| 24 |
|
| 25 |
-
**
|
| 26 |
|
|
|
|
| 27 |
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
-
|
| 34 |
|
| 35 |
-
|
| 36 |
|
| 37 |
-
|
| 38 |
|
| 39 |
-
- **
|
| 40 |
|
| 41 |
-
- **
|
| 42 |
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
- **Network restrictions** - only HTTP/HTTPS allowed## Architecture
|
| 46 |
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
```
|
| 50 |
|
| 51 |
### π Browser Automationβββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 52 |
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
| 56 |
|
| 57 |
-
- **Element interaction** - click, type, waitβ ββββββββββββββββββββββββββββββββββββββββββββββββ β
|
| 58 |
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
- **One-shot API** - execute code β test UI β get resultsβ β β β
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
|
| 67 |
-
|
| 68 |
|
| 69 |
-
|
| 70 |
|
| 71 |
-
- **
|
| 72 |
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
β β β β β β β β β β
|
| 76 |
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
-
β β β β β’
|
| 80 |
|
| 81 |
-
|
| 82 |
|
| 83 |
-
### GET /preview/{uuid} - Get Live Preview β β β ββββββββββββββββ ββββββββββββββββ β β β
|
|
|
|
|
|
|
| 84 |
|
| 85 |
### POST /browser/test - Test UI with Browserβ β ββββββββββββββββββββββββββββββββββββββββββ β β
|
| 86 |
|
|
|
|
|
|
|
| 87 |
### POST /browser/execute_and_test - One-Shot Execute + Testβ ββββββββββββββββββββββββββββββββββββββββββββββββ β
|
| 88 |
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
Full API documentation available at the Space URL.```
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
|
|
|
| 94 |
|
| 95 |
-
|
| 96 |
|
|
|
|
|
|
|
|
|
|
| 97 |
|
|
|
|
| 98 |
|
| 99 |
-
|
| 100 |
|
| 101 |
-
|
| 102 |
|
| 103 |
-
|
| 104 |
|
| 105 |
-
- **
|
| 106 |
|
| 107 |
-
|
|
|
|
|
|
|
| 108 |
|
| 109 |
-
### π« Resource Limits
|
| 110 |
-
- **Memory**: 256MB per container
|
| 111 |
-
- **CPU**: 50% of one core
|
| 112 |
-
- **Timeout**: 30 seconds default
|
| 113 |
- **Network**: Disabled (network_mode="none")
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
- **No file system persistence**
|
| 118 |
-
|
|
|
|
|
|
|
| 119 |
- **Automatic cleanup** after execution
|
| 120 |
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
-
|
|
|
|
|
|
|
| 124 |
|
| 125 |
-
#### 1. SDK
|
| 126 |
```yaml
|
| 127 |
-
|
|
|
|
|
|
|
| 128 |
```
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
- Python
|
| 133 |
-
|
| 134 |
-
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
-
#### 3. Requirements
|
| 138 |
```txt
|
| 139 |
-
fastapi
|
| 140 |
-
uvicorn[standard]
|
| 141 |
-
docker
|
| 142 |
-
pydantic
|
| 143 |
-
```
|
| 144 |
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
-
### Step 1: Create Hugging Face Space
|
| 148 |
```bash
|
| 149 |
-
|
|
|
|
|
|
|
| 150 |
# Name: your-docker-sandbox
|
| 151 |
-
|
|
|
|
|
|
|
| 152 |
```
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
python deploy_docker_space.py
|
| 157 |
```
|
| 158 |
|
|
|
|
| 1 |
+
---------
|
| 2 |
+
|
| 3 |
+
title: Landrun Sandbox + Browser Automation
|
| 4 |
+
|
| 5 |
+
emoji: πtitle: Landrun Sandbox + Browser Automationtitle: Docker Sandbox
|
| 6 |
+
|
| 7 |
+
colorFrom: purple
|
| 8 |
+
|
| 9 |
+
colorTo: blueemoji: ππemoji: π³
|
| 10 |
+
|
| 11 |
+
sdk: docker
|
| 12 |
|
| 13 |
+
app_file: app.pycolorFrom: purplecolorFrom: blue
|
| 14 |
|
| 15 |
+
pinned: false
|
| 16 |
|
| 17 |
+
license: mitcolorTo: bluecolorTo: purple
|
| 18 |
|
| 19 |
+
---
|
| 20 |
|
| 21 |
sdk: dockersdk: docker
|
| 22 |
|
| 23 |
+
# π Landrun Sandbox + Browser Automation
|
| 24 |
+
|
| 25 |
pinned: truepinned: false
|
| 26 |
|
| 27 |
+
**Kernel-Level Code Execution Sandbox with Automated UI Testing**
|
| 28 |
+
|
| 29 |
license: mitlicense: mit
|
| 30 |
|
| 31 |
+
Execute code with maximum security using **Landrun** (Linux Landlock kernel security) and automatically test UIs with **Playwright** browser automation.
|
| 32 |
+
|
| 33 |
------
|
| 34 |
|
| 35 |
+
## β¨ Features
|
| 36 |
|
| 37 |
|
|
|
|
| 38 |
|
| 39 |
+
### π Landrun Security
|
| 40 |
|
| 41 |
+
- **Kernel-level isolation** using Linux Landlock LSM# π Landrun Sandbox + Browser Automation# π³ Docker Sandbox Executor
|
| 42 |
|
| 43 |
+
- **Zero-trust execution** with restricted filesystem access
|
| 44 |
|
| 45 |
+
- **Read-only system files** - only `/tmp/sandbox` is writable
|
| 46 |
|
| 47 |
+
- **Network restrictions** - only HTTP/HTTPS allowed
|
| 48 |
|
| 49 |
+
- **10-second timeout** protection**Kernel-Level Code Execution Sandbox + Automated UI Testing****Secure code execution in isolated Docker containers**
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
+
### π Browser Automation
|
| 54 |
|
| 55 |
+
- **Playwright Chromium** for automated UI testing
|
| 56 |
|
| 57 |
+
- **Screenshot capture** before/after actionsExecute code with maximum security using **Landrun** (Linux Landlock kernel security) and automatically test UIs with **Playwright** browser automation.## Features
|
| 58 |
|
| 59 |
+
- **Element interaction** - click, type, wait, get text
|
| 60 |
|
| 61 |
+
- **One-shot API** - execute code β test UI β get results
|
| 62 |
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
### π Supported Languages## β¨ Featuresβ
**Isolated execution** - Each code run in separate container
|
| 66 |
+
|
| 67 |
+
- **Python 3.11** - with stdlib + compilers (gcc, g++)
|
| 68 |
+
|
| 69 |
+
- **JavaScript (Node.js)** - server-side executionβ
**Resource limits** - 256MB RAM, 50% CPU per execution
|
| 70 |
+
|
| 71 |
+
- **React (JSX)** - client-side components with live preview
|
| 72 |
+
|
| 73 |
+
- **HTML + CSS** - static pages with full styling### π Landrun Securityβ
**Network disabled** - Maximum security
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
## π‘ API Endpoints- **Kernel-level isolation** using Linux Landlock LSMβ
**Auto-cleanup** - Containers destroyed after execution
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
### 1. Execute Code- **Zero-trust execution** with restricted filesystem accessβ
**Multiple languages** - Python, JavaScript, React, HTML
|
| 82 |
+
|
| 83 |
+
```bash
|
| 84 |
+
|
| 85 |
+
POST /execute- **Read-only system files** - only `/tmp/sandbox` is writable
|
| 86 |
+
|
| 87 |
+
Content-Type: application/json
|
| 88 |
|
| 89 |
- **Network restrictions** - only HTTP/HTTPS allowed## Architecture
|
| 90 |
|
| 91 |
+
{
|
| 92 |
+
|
| 93 |
+
"language": "react",- **10-second timeout** protection
|
| 94 |
+
|
| 95 |
+
"code": "export default function App() { return <h1>Hello!</h1>; }"
|
| 96 |
+
|
| 97 |
+
}```
|
| 98 |
|
| 99 |
```
|
| 100 |
|
| 101 |
### π Browser Automationβββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 102 |
|
| 103 |
+
### 2. Get Live Preview
|
| 104 |
+
|
| 105 |
+
```bash- **Playwright Chromium** for automated UI testingβ Hugging Face Space (Docker SDK) β
|
| 106 |
+
|
| 107 |
+
GET /preview/{uuid}
|
| 108 |
|
| 109 |
+
```- **Screenshot capture** before/after actionsβ β
|
| 110 |
|
|
|
|
| 111 |
|
| 112 |
+
|
| 113 |
+
### 3. Test UI with Browser- **Element interaction** - click, type, waitβ ββββββββββββββββββββββββββββββββββββββββββββββββ β
|
| 114 |
+
|
| 115 |
+
```bash
|
| 116 |
+
|
| 117 |
+
POST /browser/test- **Text extraction** from elementsβ β FastAPI Server (app_docker.py) β β
|
| 118 |
+
|
| 119 |
+
Content-Type: application/json
|
| 120 |
|
| 121 |
- **One-shot API** - execute code β test UI β get resultsβ β β β
|
| 122 |
|
| 123 |
+
{
|
| 124 |
+
|
| 125 |
+
"preview_url": "/preview/uuid",β β ββββββββββββββββββββββββββββββββββββββββββ β β
|
| 126 |
|
| 127 |
+
"actions": [
|
| 128 |
|
| 129 |
+
{"type": "click", "selector": "button"},### π Supported Languagesβ β β Docker Engine (in Space) β β β
|
| 130 |
|
| 131 |
+
{"type": "screenshot"}
|
| 132 |
|
| 133 |
+
]- **Python 3.11** - with stdlib + compilersβ β β β β β
|
| 134 |
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
```- **JavaScript (Node.js)** - server-side executionβ β β ββββββββββββββββ ββββββββββββββββ β β β
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
### 4. Execute + Test (One-Shot)- **React (JSX)** - client-side components with live previewβ β β β Python:3.11 β β Node:18 β β β β
|
| 142 |
+
|
| 143 |
+
```bash
|
| 144 |
+
|
| 145 |
+
POST /browser/execute_and_test- **HTML + CSS** - static pages with full stylingβ β β β Container β β Container β β β β
|
| 146 |
+
|
| 147 |
+
Content-Type: application/json
|
| 148 |
|
| 149 |
β β β β β β β β β β
|
| 150 |
|
| 151 |
+
{
|
| 152 |
+
|
| 153 |
+
"language": "react",## π‘ API Endpointsβ β β β β’ 256MB RAM β β β’ 256MB RAM β β β β
|
| 154 |
+
|
| 155 |
+
"code": "export default function App() { return <button>Click</button>; }",
|
| 156 |
+
|
| 157 |
+
"actions": [β β β β β’ 50% CPU β β β’ 50% CPU β β β β
|
| 158 |
+
|
| 159 |
+
{"type": "click", "selector": "button"},
|
| 160 |
|
| 161 |
+
{"type": "screenshot"}### POST /execute - Execute Code with Landrunβ β β β β’ No Network β β β’ No Network β β β β
|
| 162 |
|
| 163 |
+
]
|
| 164 |
|
| 165 |
+
}### GET /preview/{uuid} - Get Live Preview β β β ββββββββββββββββ ββββββββββββββββ β β β
|
| 166 |
+
|
| 167 |
+
```
|
| 168 |
|
| 169 |
### POST /browser/test - Test UI with Browserβ β ββββββββββββββββββββββββββββββββββββββββββ β β
|
| 170 |
|
| 171 |
+
## π― Quick Start
|
| 172 |
+
|
| 173 |
### POST /browser/execute_and_test - One-Shot Execute + Testβ ββββββββββββββββββββββββββββββββββββββββββββββββ β
|
| 174 |
|
| 175 |
+
### Python Example
|
| 176 |
+
|
| 177 |
+
```pythonβββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 178 |
+
|
| 179 |
+
import requests
|
| 180 |
|
| 181 |
Full API documentation available at the Space URL.```
|
| 182 |
|
| 183 |
+
response = requests.post(
|
| 184 |
+
|
| 185 |
+
"https://speedofmastery-hmm.hf.space/browser/execute_and_test",
|
| 186 |
+
|
| 187 |
+
json={
|
| 188 |
+
|
| 189 |
+
"language": "react",## π Quick Start## Security Features
|
| 190 |
+
|
| 191 |
+
"code": """
|
| 192 |
+
|
| 193 |
+
export default function App() {
|
| 194 |
+
|
| 195 |
+
const [count, setCount] = React.useState(0);
|
| 196 |
+
|
| 197 |
+
return (Visit: **https://speedofmastery-hmm.hf.space**### π‘οΈ Container Isolation
|
| 198 |
+
|
| 199 |
+
<div>
|
| 200 |
+
|
| 201 |
+
<h1>Count: {count}</h1>- Each execution runs in a **separate Docker container**
|
| 202 |
|
| 203 |
+
<button onClick={() => setCount(count + 1)}>Increment</button>
|
| 204 |
|
| 205 |
+
</div>## π License- Containers are **destroyed after execution**
|
| 206 |
|
| 207 |
+
);
|
| 208 |
+
|
| 209 |
+
}- **No persistent storage** between executions
|
| 210 |
|
| 211 |
+
""",
|
| 212 |
|
| 213 |
+
"actions": [MIT License
|
| 214 |
|
| 215 |
+
{"type": "click", "selector": "button"},
|
| 216 |
|
| 217 |
+
{"type": "screenshot"}### π« Resource Limits
|
| 218 |
|
| 219 |
+
]- **Memory**: 256MB per container
|
| 220 |
|
| 221 |
+
}- **CPU**: 50% of one core
|
| 222 |
+
|
| 223 |
+
)- **Timeout**: 30 seconds default
|
| 224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
- **Network**: Disabled (network_mode="none")
|
| 226 |
|
| 227 |
+
result = response.json()
|
| 228 |
+
|
| 229 |
+
print(result['status']) # 'success'### π Security Constraints
|
| 230 |
+
|
| 231 |
+
```- **No root access** in containers
|
| 232 |
+
|
| 233 |
- **No file system persistence**
|
| 234 |
+
|
| 235 |
+
## π Security- **No network access**
|
| 236 |
+
|
| 237 |
- **Automatic cleanup** after execution
|
| 238 |
|
| 239 |
+
- **Landrun Sandbox:** Kernel-level isolation using Linux Landlock
|
| 240 |
+
|
| 241 |
+
- **Read-only:** `/usr`, `/lib`, `/etc` are read-only## Hugging Face Space Configuration
|
| 242 |
+
|
| 243 |
+
- **Writable:** Only `/tmp/sandbox` is writable
|
| 244 |
+
|
| 245 |
+
- **Network:** TCP ports 80, 443 only### Required Space Settings
|
| 246 |
|
| 247 |
+
- **Timeout:** 10 seconds max execution
|
| 248 |
+
|
| 249 |
+
- **Browser:** Headless Chromium with 5s action timeout#### 1. SDK
|
| 250 |
|
|
|
|
| 251 |
```yaml
|
| 252 |
+
|
| 253 |
+
## π οΈ Technology Stacksdk: docker
|
| 254 |
+
|
| 255 |
```
|
| 256 |
|
| 257 |
+
- **Landrun**: Go-based Linux Landlock sandbox
|
| 258 |
+
|
| 259 |
+
- **FastAPI**: Modern async Python web framework#### 2. Dockerfile.sandbox
|
| 260 |
+
|
| 261 |
+
- **Playwright**: Browser automation frameworkUse the provided `Dockerfile.sandbox` which includes:
|
| 262 |
+
|
| 263 |
+
- **Chromium**: Headless browser engine- Python 3.11 base
|
| 264 |
+
|
| 265 |
+
- **Docker**: Multi-stage container build- Node.js for React/JavaScript
|
| 266 |
+
|
| 267 |
+
- **Python 3.11**: Runtime environment with compilers- Docker-in-Docker (DinD) support
|
| 268 |
+
|
| 269 |
+
- **Node.js**: JavaScript execution- Non-root user execution
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
## π Browser Actions#### 3. Requirements
|
| 274 |
|
|
|
|
| 275 |
```txt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
|
| 277 |
+
| Action | Description |fastapi
|
| 278 |
+
|
| 279 |
+
|--------|-------------|uvicorn[standard]
|
| 280 |
+
|
| 281 |
+
| `click` | Click element by selector |docker
|
| 282 |
+
|
| 283 |
+
| `type` | Type text into input field |pydantic
|
| 284 |
+
|
| 285 |
+
| `get_text` | Extract text from element |```
|
| 286 |
+
|
| 287 |
+
| `wait` | Wait for element to appear |
|
| 288 |
+
|
| 289 |
+
| `screenshot` | Capture screenshot (base64) |## Deployment Steps
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
## π License### Step 1: Create Hugging Face Space
|
| 294 |
|
|
|
|
| 295 |
```bash
|
| 296 |
+
|
| 297 |
+
MIT License - Free to use and modify# Create new space with Docker SDK
|
| 298 |
+
|
| 299 |
# Name: your-docker-sandbox
|
| 300 |
+
|
| 301 |
+
## π Links# SDK: Docker
|
| 302 |
+
|
| 303 |
```
|
| 304 |
|
| 305 |
+
- **Live Demo:** [speedofmastery-hmm.hf.space](https://speedofmastery-hmm.hf.space)
|
| 306 |
+
|
| 307 |
+
- **Landrun GitHub:** [github.com/zouuup/landrun](https://github.com/zouuup/landrun)### Step 2: Upload Files
|
| 308 |
+
|
| 309 |
+
- **Playwright Docs:** [playwright.dev](https://playwright.dev)```bash
|
| 310 |
+
|
| 311 |
python deploy_docker_space.py
|
| 312 |
```
|
| 313 |
|