Speedofmastery commited on
Commit
d2a4863
ยท
1 Parent(s): 98d1f5d

Auto-commit: README.md updated

Browse files
Files changed (1) hide show
  1. README.md +59 -743
README.md CHANGED
@@ -1,775 +1,91 @@
1
- ------------
2
-
3
  title: Landrun Sandbox + Browser Automation
4
-
5
- emoji: ๐Ÿ”’title: Landrun Sandbox + Browser Automation
6
-
7
  colorFrom: purple
8
-
9
- colorTo: blueemoji: ๐Ÿ”’title: Landrun Sandbox + Browser Automationtitle: Docker Sandbox
10
-
11
  sdk: docker
12
-
13
- app_file: app.pycolorFrom: purple
14
-
15
  pinned: false
16
-
17
- license: mitcolorTo: blueemoji: ๐Ÿ”’๐ŸŒemoji: ๐Ÿณ
18
-
19
  ---
20
 
21
- sdk: docker
22
-
23
- # ๐Ÿ”’ Landrun Sandbox + Browser Automation
24
-
25
- app_file: app.pycolorFrom: purplecolorFrom: blue
26
 
27
  **Kernel-Level Code Execution Sandbox with Automated UI Testing**
28
 
29
- pinned: false
30
-
31
  Execute code with maximum security using **Landrun** (Linux Landlock kernel security) and automatically test UIs with **Playwright** browser automation.
32
 
33
- license: mitcolorTo: bluecolorTo: purple
34
-
35
- ## โœจ Features
36
-
37
- ---
38
-
39
- ### ๐Ÿ”’ Landrun Security
40
-
41
- sdk: dockersdk: docker
42
-
43
- - **Kernel-level isolation** using Linux Landlock LSM
44
-
45
- - **Zero-trust execution** with restricted filesystem access# ๐Ÿ”’ Landrun Sandbox + Browser Automation
46
-
47
- - **Read-only system files** - only `/tmp/sandbox` is writable
48
-
49
- - **Network restrictions** - only HTTP/HTTPS allowedpinned: truepinned: false
50
-
51
- - **10-second timeout** protection
52
-
53
- **Kernel-Level Code Execution Sandbox with Automated UI Testing**
54
-
55
- ### ๐ŸŒ Browser Automation
56
-
57
- license: mitlicense: mit
58
-
59
- - **Playwright Chromium** for automated UI testing
60
-
61
- - **Screenshot capture** before/after actionsExecute code with maximum security using **Landrun** (Linux Landlock kernel security) and automatically test UIs with **Playwright** browser automation.
62
-
63
- - **Element interaction** - click, type, wait, get text
64
-
65
- - **One-shot API** - execute code โ†’ test UI โ†’ get results------
66
-
67
-
68
-
69
- ### ๐Ÿš€ Supported Languages## โœจ Features
70
-
71
-
72
-
73
- - **Python 3.11** - with stdlib + compilers (gcc, g++)
74
-
75
- - **JavaScript (Node.js)** - server-side execution
76
-
77
- - **React (JSX)** - client-side components with live preview### ๐Ÿ”’ Landrun Security
78
-
79
- - **HTML + CSS** - static pages with full styling
80
-
81
- - **Kernel-level isolation** using Linux Landlock LSM# ๐Ÿ”’ Landrun Sandbox + Browser Automation# ๐Ÿณ Docker Sandbox Executor
82
-
83
- ## ๐Ÿ“ก API Endpoints
84
-
85
- - **Zero-trust execution** with restricted filesystem access
86
-
87
- ### 1. Execute Code
88
-
89
- - **Read-only system files** - only `/tmp/sandbox` is writable
90
-
91
- ```bash
92
-
93
- POST /execute- **Network restrictions** - only HTTP/HTTPS allowed
94
-
95
- Content-Type: application/json
96
-
97
- - **10-second timeout** protection**Kernel-Level Code Execution Sandbox + Automated UI Testing****Secure code execution in isolated Docker containers**
98
-
99
- {
100
-
101
- "language": "react",
102
-
103
- "code": "export default function App() { return <h1>Hello!</h1>; }"
104
-
105
- }### ๐ŸŒ Browser Automation
106
-
107
- ```
108
-
109
- - **Playwright Chromium** for automated UI testing
110
-
111
- ### 2. Get Live Preview
112
-
113
- - **Screenshot capture** before/after actionsExecute code with maximum security using **Landrun** (Linux Landlock kernel security) and automatically test UIs with **Playwright** browser automation.## Features
114
-
115
- ```bash
116
-
117
- GET /preview/{uuid}- **Element interaction** - click, type, wait, get text
118
-
119
- ```
120
-
121
- - **One-shot API** - execute code โ†’ test UI โ†’ get results
122
-
123
- ### 3. Test UI with Browser
124
-
125
-
126
-
127
- ```bash
128
-
129
- POST /browser/test### ๐Ÿš€ Supported Languages## โœจ Featuresโœ… **Isolated execution** - Each code run in separate container
130
-
131
- Content-Type: application/json
132
-
133
- - **Python 3.11** - with stdlib + compilers (gcc, g++)
134
-
135
- {
136
-
137
- "preview_url": "/preview/uuid",- **JavaScript (Node.js)** - server-side executionโœ… **Resource limits** - 256MB RAM, 50% CPU per execution
138
-
139
- "actions": [
140
-
141
- {"type": "click", "selector": "button"},- **React (JSX)** - client-side components with live preview
142
-
143
- {"type": "screenshot"}
144
-
145
- ]- **HTML + CSS** - static pages with full styling### ๐Ÿ”’ Landrun Securityโœ… **Network disabled** - Maximum security
146
-
147
- }
148
-
149
- ```
150
-
151
-
152
-
153
- ### 4. Execute + Test (One-Shot)## ๐Ÿ“ก API Endpoints- **Kernel-level isolation** using Linux Landlock LSMโœ… **Auto-cleanup** - Containers destroyed after execution
154
-
155
-
156
-
157
- ```bash
158
-
159
- POST /browser/execute_and_test
160
-
161
- Content-Type: application/json### 1. Execute Code- **Zero-trust execution** with restricted filesystem accessโœ… **Multiple languages** - Python, JavaScript, React, HTML
162
-
163
-
164
-
165
- {```bash
166
-
167
- "language": "react",
168
-
169
- "code": "export default function App() { return <button>Click</button>; }",POST /execute- **Read-only system files** - only `/tmp/sandbox` is writable
170
-
171
- "actions": [
172
-
173
- {"type": "click", "selector": "button"},Content-Type: application/json
174
-
175
- {"type": "screenshot"}
176
-
177
- ]- **Network restrictions** - only HTTP/HTTPS allowed## Architecture
178
-
179
- }
180
-
181
- ```{
182
-
183
-
184
-
185
- ## ๐ŸŽฏ Quick Start "language": "react",- **10-second timeout** protection
186
-
187
-
188
-
189
- ### Python Example "code": "export default function App() { return <h1>Hello!</h1>; }"
190
-
191
-
192
-
193
- ```python}```
194
-
195
- import requests
196
-
197
- ```
198
-
199
- response = requests.post(
200
-
201
- "https://speedofmastery-hmm.hf.space/browser/execute_and_test",### ๐ŸŒ Browser Automationโ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
202
-
203
- json={
204
-
205
- "language": "react",### 2. Get Live Preview
206
-
207
- "code": """
208
-
209
- export default function App() {```bash- **Playwright Chromium** for automated UI testingโ”‚ Hugging Face Space (Docker SDK) โ”‚
210
-
211
- const [count, setCount] = React.useState(0);
212
-
213
- return (GET /preview/{uuid}
214
-
215
- <div>
216
-
217
- <h1>Count: {count}</h1>```- **Screenshot capture** before/after actionsโ”‚ โ”‚
218
-
219
- <button onClick={() => setCount(count + 1)}>Increment</button>
220
-
221
- </div>
222
-
223
- );
224
-
225
- }### 3. Test UI with Browser- **Element interaction** - click, type, waitโ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
226
-
227
- """,
228
-
229
- "actions": [```bash
230
-
231
- {"type": "click", "selector": "button"},
232
-
233
- {"type": "screenshot"}POST /browser/test- **Text extraction** from elementsโ”‚ โ”‚ FastAPI Server (app_docker.py) โ”‚ โ”‚
234
-
235
- ]
236
-
237
- }Content-Type: application/json
238
-
239
- )
240
-
241
- - **One-shot API** - execute code โ†’ test UI โ†’ get resultsโ”‚ โ”‚ โ”‚ โ”‚
242
-
243
- result = response.json()
244
-
245
- print(result['status']) # 'success'{
246
-
247
- ```
248
-
249
- "preview_url": "/preview/uuid",โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚
250
-
251
- ## ๐Ÿ”’ Security
252
-
253
- "actions": [
254
-
255
- - **Landrun Sandbox:** Kernel-level isolation using Linux Landlock
256
-
257
- - **Read-only:** `/usr`, `/lib`, `/etc` are read-only {"type": "click", "selector": "button"},### ๐Ÿš€ Supported Languagesโ”‚ โ”‚ โ”‚ Docker Engine (in Space) โ”‚ โ”‚ โ”‚
258
-
259
- - **Writable:** Only `/tmp/sandbox` is writable
260
-
261
- - **Network:** TCP ports 80, 443 only {"type": "screenshot"}
262
-
263
- - **Timeout:** 10 seconds max execution
264
-
265
- - **Browser:** Headless Chromium with 5s action timeout ]- **Python 3.11** - with stdlib + compilersโ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
266
-
267
-
268
-
269
- ## ๐Ÿ› ๏ธ Technology Stack}
270
 
 
 
 
 
 
 
271
 
272
-
273
- - **Landrun**: Go-based Linux Landlock sandbox```- **JavaScript (Node.js)** - server-side executionโ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚
274
-
275
- - **FastAPI**: Modern async Python web framework
276
-
277
- - **Playwright**: Browser automation framework
278
-
279
- - **Chromium**: Headless browser engine
280
-
281
- - **Docker**: Multi-stage container build### 4. Execute + Test (One-Shot)- **React (JSX)** - client-side components with live previewโ”‚ โ”‚ โ”‚ โ”‚ Python:3.11 โ”‚ โ”‚ Node:18 โ”‚ โ”‚ โ”‚ โ”‚
282
-
283
- - **Python 3.11**: Runtime environment with compilers
284
-
285
- - **Node.js**: JavaScript execution```bash
286
-
287
-
288
-
289
- ## ๐Ÿ“Š Browser ActionsPOST /browser/execute_and_test- **HTML + CSS** - static pages with full stylingโ”‚ โ”‚ โ”‚ โ”‚ Container โ”‚ โ”‚ Container โ”‚ โ”‚ โ”‚ โ”‚
290
-
291
-
292
-
293
- | Action | Description |Content-Type: application/json
294
-
295
- |--------|-------------|
296
-
297
- | `click` | Click element by selector |โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
298
-
299
- | `type` | Type text into input field |
300
-
301
- | `get_text` | Extract text from element |{
302
-
303
- | `wait` | Wait for element to appear |
304
-
305
- | `screenshot` | Capture screenshot (base64) | "language": "react",## ๐Ÿ“ก API Endpointsโ”‚ โ”‚ โ”‚ โ”‚ โ€ข 256MB RAM โ”‚ โ”‚ โ€ข 256MB RAM โ”‚ โ”‚ โ”‚ โ”‚
306
-
307
-
308
-
309
- ## ๐Ÿ“„ License "code": "export default function App() { return <button>Click</button>; }",
310
-
311
-
312
-
313
- MIT License - Free to use and modify "actions": [โ”‚ โ”‚ โ”‚ โ”‚ โ€ข 50% CPU โ”‚ โ”‚ โ€ข 50% CPU โ”‚ โ”‚ โ”‚ โ”‚
314
-
315
-
316
-
317
- ## ๐Ÿ”— Links {"type": "click", "selector": "button"},
318
-
319
-
320
-
321
- - **Live Demo:** [speedofmastery-hmm.hf.space](https://speedofmastery-hmm.hf.space) {"type": "screenshot"}### POST /execute - Execute Code with Landrunโ”‚ โ”‚ โ”‚ โ”‚ โ€ข No Network โ”‚ โ”‚ โ€ข No Network โ”‚ โ”‚ โ”‚ โ”‚
322
-
323
- - **Landrun GitHub:** [github.com/zouuup/landrun](https://github.com/zouuup/landrun)
324
-
325
- - **Playwright Docs:** [playwright.dev](https://playwright.dev) ]
326
-
327
-
328
- }### GET /preview/{uuid} - Get Live Preview โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚
329
-
330
- ```
331
-
332
- ### POST /browser/test - Test UI with Browserโ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€๏ฟฝ๏ฟฝโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚
333
-
334
- ## ๐ŸŽฏ Quick Start
335
-
336
- ### POST /browser/execute_and_test - One-Shot Execute + Testโ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
337
-
338
- ### Python Example
339
-
340
- ```pythonโ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
341
-
342
- import requests
343
-
344
- Full API documentation available at the Space URL.```
345
-
346
- response = requests.post(
347
-
348
- "https://speedofmastery-hmm.hf.space/browser/execute_and_test",
349
-
350
- json={
351
-
352
- "language": "react",## ๐Ÿš€ Quick Start## Security Features
353
-
354
- "code": """
355
-
356
- export default function App() {
357
-
358
- const [count, setCount] = React.useState(0);
359
-
360
- return (Visit: **https://speedofmastery-hmm.hf.space**### ๐Ÿ›ก๏ธ Container Isolation
361
-
362
- <div>
363
-
364
- <h1>Count: {count}</h1>- Each execution runs in a **separate Docker container**
365
-
366
- <button onClick={() => setCount(count + 1)}>Increment</button>
367
-
368
- </div>## ๐Ÿ“„ License- Containers are **destroyed after execution**
369
-
370
- );
371
-
372
- }- **No persistent storage** between executions
373
-
374
- """,
375
-
376
- "actions": [MIT License
377
-
378
- {"type": "click", "selector": "button"},
379
-
380
- {"type": "screenshot"}### ๐Ÿšซ Resource Limits
381
-
382
- ]- **Memory**: 256MB per container
383
-
384
- }- **CPU**: 50% of one core
385
-
386
- )- **Timeout**: 30 seconds default
387
-
388
- - **Network**: Disabled (network_mode="none")
389
-
390
- result = response.json()
391
-
392
- print(result['status']) # 'success'### ๐Ÿ”’ Security Constraints
393
-
394
- ```- **No root access** in containers
395
-
396
- - **No file system persistence**
397
-
398
- ## ๐Ÿ”’ Security- **No network access**
399
-
400
- - **Automatic cleanup** after execution
401
-
402
- - **Landrun Sandbox:** Kernel-level isolation using Linux Landlock
403
-
404
- - **Read-only:** `/usr`, `/lib`, `/etc` are read-only## Hugging Face Space Configuration
405
-
406
- - **Writable:** Only `/tmp/sandbox` is writable
407
-
408
- - **Network:** TCP ports 80, 443 only### Required Space Settings
409
-
410
- - **Timeout:** 10 seconds max execution
411
-
412
- - **Browser:** Headless Chromium with 5s action timeout#### 1. SDK
413
-
414
- ```yaml
415
-
416
- ## ๐Ÿ› ๏ธ Technology Stacksdk: docker
417
-
418
- ```
419
-
420
- - **Landrun**: Go-based Linux Landlock sandbox
421
-
422
- - **FastAPI**: Modern async Python web framework#### 2. Dockerfile.sandbox
423
-
424
- - **Playwright**: Browser automation frameworkUse the provided `Dockerfile.sandbox` which includes:
425
-
426
- - **Chromium**: Headless browser engine- Python 3.11 base
427
-
428
- - **Docker**: Multi-stage container build- Node.js for React/JavaScript
429
-
430
- - **Python 3.11**: Runtime environment with compilers- Docker-in-Docker (DinD) support
431
-
432
- - **Node.js**: JavaScript execution- Non-root user execution
433
-
434
-
435
-
436
- ## ๐Ÿ“Š Browser Actions#### 3. Requirements
437
-
438
- ```txt
439
-
440
- | Action | Description |fastapi
441
-
442
- |--------|-------------|uvicorn[standard]
443
-
444
- | `click` | Click element by selector |docker
445
-
446
- | `type` | Type text into input field |pydantic
447
-
448
- | `get_text` | Extract text from element |```
449
-
450
- | `wait` | Wait for element to appear |
451
-
452
- | `screenshot` | Capture screenshot (base64) |## Deployment Steps
453
-
454
-
455
-
456
- ## ๐Ÿ“„ License### Step 1: Create Hugging Face Space
457
-
458
- ```bash
459
-
460
- MIT License - Free to use and modify# Create new space with Docker SDK
461
-
462
- # Name: your-docker-sandbox
463
-
464
- ## ๐Ÿ”— Links# SDK: Docker
465
-
466
- ```
467
-
468
- - **Live Demo:** [speedofmastery-hmm.hf.space](https://speedofmastery-hmm.hf.space)
469
-
470
- - **Landrun GitHub:** [github.com/zouuup/landrun](https://github.com/zouuup/landrun)### Step 2: Upload Files
471
-
472
- - **Playwright Docs:** [playwright.dev](https://playwright.dev)```bash
473
-
474
- python deploy_docker_space.py
475
- ```
476
-
477
- Or manually:
478
- ```bash
479
- # Clone your space
480
- git clone https://huggingface.co/spaces/YOUR_USERNAME/your-docker-sandbox
481
- cd your-docker-sandbox
482
-
483
- # Copy files
484
- cp Dockerfile.sandbox Dockerfile
485
- cp app_docker.py app.py
486
- cp requirements.txt .
487
-
488
- # Add README
489
- cp README_DOCKER.md README.md
490
-
491
- # Commit and push
492
- git add .
493
- git commit -m "Deploy Docker sandbox"
494
- git push
495
- ```
496
-
497
- ### Step 3: Enable Docker in Space Settings
498
- 1. Go to Space Settings
499
- 2. Under "Advanced", enable **"Docker SDK"**
500
- 3. Set **"Timeout"** to 60+ seconds
501
- 4. Save settings
502
-
503
- ## API Usage
504
-
505
- ### Endpoint
506
- ```
507
- POST https://YOUR_USERNAME-your-docker-sandbox.hf.space/execute
508
- ```
509
-
510
- ### Request Format
511
- ```json
512
- {
513
- "language": "python",
514
- "code": "print('Hello from Docker!')",
515
- "timeout": 30
516
- }
517
- ```
518
 
519
  ### Supported Languages
520
- - `python` - Python 3.11 in Alpine container
521
- - `javascript` - Node.js 18 in Alpine container
522
- - `react` - Client-side React (no container needed)
523
- - `html` - Pure HTML (no container needed)
524
-
525
- ### Response Format
526
- ```json
527
- {
528
- "status": "success",
529
- "preview_url": "data:text/html;base64,...",
530
- "terminal_view_url": "data:text/html;base64,...",
531
- "execution_time": 0.234,
532
- "docker_enabled": true
533
- }
534
- ```
535
-
536
- ## Example: Python Code Execution
537
-
538
- ### PowerShell
539
- ```powershell
540
- $apiUrl = "https://YOUR_USERNAME-your-docker-sandbox.hf.space/execute"
541
-
542
- $code = @"
543
- import sys
544
- print(f'Python {sys.version}')
545
- print('Running in Docker container!')
546
- for i in range(5):
547
- print(f'Count: {i}')
548
- "@
549
-
550
- $body = @{
551
- language = "python"
552
- code = $code
553
- timeout = 30
554
- } | ConvertTo-Json
555
-
556
- $response = Invoke-RestMethod -Uri $apiUrl -Method Post -Body $body -ContentType "application/json"
557
-
558
- # Display terminal output
559
- $terminalHtml = "<html><body><iframe src='$($response.terminal_view_url)' style='width:100%;height:100vh;border:none;'></iframe></body></html>"
560
- $terminalHtml | Out-File -FilePath "docker_terminal.html"
561
- Start-Process "docker_terminal.html"
562
- ```
563
-
564
- ### JavaScript (Node.js)
565
- ```javascript
566
- const apiUrl = "https://YOUR_USERNAME-your-docker-sandbox.hf.space/execute";
567
 
568
- const code = `
569
- console.log('Node.js in Docker!');
570
- console.log('Environment:', process.version);
571
- const data = [1, 2, 3, 4, 5];
572
- console.log('Sum:', data.reduce((a, b) => a + b, 0));
573
- `;
574
 
575
- fetch(apiUrl, {
576
- method: 'POST',
577
- headers: { 'Content-Type': 'application/json' },
578
- body: JSON.stringify({
579
- language: 'javascript',
580
- code: code,
581
- timeout: 30
582
- })
583
- })
584
- .then(res => res.json())
585
- .then(data => {
586
- console.log('Execution time:', data.execution_time);
587
- // Open terminal view
588
- const iframe = document.createElement('iframe');
589
- iframe.src = data.terminal_view_url;
590
- iframe.style = 'width:100%;height:100vh;border:none;';
591
- document.body.appendChild(iframe);
592
- });
593
- ```
594
 
595
- ### React Example
596
- ```javascript
597
- const reactCode = `
598
- const { useState } = React;
599
 
600
- function Counter() {
601
- const [count, setCount] = useState(0);
602
-
603
- return (
604
- <div style={{ padding: '40px', textAlign: 'center', fontFamily: 'Arial' }}>
605
- <h1 style={{ fontSize: '48px', color: '#667eea' }}>Counter: {count}</h1>
606
- <button
607
- onClick={() => setCount(count + 1)}
608
- style={{
609
- padding: '15px 30px',
610
- fontSize: '20px',
611
- background: '#667eea',
612
- color: 'white',
613
- border: 'none',
614
- borderRadius: '10px',
615
- cursor: 'pointer',
616
- margin: '10px'
617
- }}
618
- >
619
- Increment
620
- </button>
621
- <button
622
- onClick={() => setCount(count - 1)}
623
- style={{
624
- padding: '15px 30px',
625
- fontSize: '20px',
626
- background: '#764ba2',
627
- color: 'white',
628
- border: 'none',
629
- borderRadius: '10px',
630
- cursor: 'pointer',
631
- margin: '10px'
632
- }}
633
- >
634
- Decrement
635
- </button>
636
- </div>
637
- );
638
- }
639
 
640
- ReactDOM.render(<Counter />, document.getElementById('root'));
641
- `;
642
 
643
- fetch(apiUrl, {
644
- method: 'POST',
645
- headers: { 'Content-Type': 'application/json' },
646
- body: JSON.stringify({
647
- language: 'react',
648
- code: reactCode
649
- })
650
- })
651
- .then(res => res.json())
652
- .then(data => {
653
- // React runs client-side, so preview_url contains the full app
654
- window.open(data.preview_url, '_blank');
655
- });
656
- ```
657
 
658
- ## Advantages of Docker Sandbox
 
 
 
659
 
660
- ### โœ… vs Regular Hugging Face Spaces
661
- 1. **Complete Isolation** - Each execution is fully isolated
662
- 2. **Resource Control** - Strict memory and CPU limits
663
- 3. **No Contamination** - Containers destroyed after use
664
- 4. **Multiple Runtimes** - Python, Node, Ruby, etc. in separate containers
665
- 5. **Security** - No network, no persistence, no escape
666
 
667
- ### โœ… vs Local Sandboxie
668
- 1. **Cloud-Native** - No local installation needed
669
- 2. **Always Available** - 24/7 API access
670
- 3. **Scalable** - Handles multiple concurrent requests
671
- 4. **Platform Independent** - Works from any device
 
672
 
673
- ### โœ… vs Process-Based Execution
674
- 1. **Better Isolation** - Container vs process boundaries
675
- 2. **Cleaner Cleanup** - No orphaned processes
676
- 3. **Reproducible** - Same environment every time
677
- 4. **Safer** - Can't access host filesystem
678
 
679
- ## Monitoring
 
 
 
 
 
 
680
 
681
- ### Health Check
682
- ```bash
683
- curl https://YOUR_USERNAME-your-docker-sandbox.hf.space/health
684
- ```
685
 
686
- Response:
687
- ```json
688
- {
689
- "status": "healthy",
690
- "docker_available": true
691
- }
692
- ```
693
-
694
- ### Container Stats
695
- The Docker executor automatically:
696
- - Removes containers after execution
697
- - Logs container lifecycle events
698
- - Tracks resource usage
699
- - Enforces timeouts
700
-
701
- ## Troubleshooting
702
-
703
- ### "Docker not available"
704
- **Solution**: Ensure Space is using Docker SDK:
705
- 1. Space Settings โ†’ SDK โ†’ Select "Docker"
706
- 2. Wait for rebuild
707
- 3. Check `/health` endpoint
708
-
709
- ### Execution Timeout
710
- **Solution**: Increase timeout in request:
711
- ```json
712
- {
713
- "language": "python",
714
- "code": "...",
715
- "timeout": 60
716
- }
717
- ```
718
-
719
- ### Container Memory Error
720
- **Solution**: Optimize code or contact HF support for higher limits
721
-
722
- ### Network Errors in Container
723
- **Expected**: Containers have `network_mode="none"` for security
724
- - React/HTML work because they run **client-side**
725
- - Python/JavaScript run **server-side** without network
726
-
727
- ## Performance
728
-
729
- ### Typical Execution Times
730
- - **Python simple**: ~0.5-1s (container startup + execution)
731
- - **JavaScript simple**: ~0.6-1.2s
732
- - **React**: ~0.1s (client-side, no container)
733
- - **HTML**: ~0.05s (client-side, no container)
734
-
735
- ### Cold Start
736
- First execution may take 2-5 seconds to pull Docker images.
737
-
738
- ## Best Practices
739
-
740
- ### 1. Choose Right Language
741
- - Use **React/HTML** for UI apps (faster, client-side)
742
- - Use **Python/JavaScript** for computation (secure, isolated)
743
-
744
- ### 2. Optimize Code
745
- - Keep execution time under 10 seconds
746
- - Avoid heavy computations in containers
747
- - Use React for interactive UIs
748
-
749
- ### 3. Handle Errors
750
- ```javascript
751
- try {
752
- const response = await fetch(apiUrl, { ... });
753
- const data = await response.json();
754
- if (data.status === 'error') {
755
- console.error('Execution failed');
756
- }
757
- } catch (error) {
758
- console.error('API error:', error);
759
- }
760
- ```
761
-
762
- ## Future Enhancements
763
-
764
- - [ ] Multi-language containers (Go, Rust, Ruby)
765
- - [ ] Custom Docker images
766
- - [ ] Volume mounting for data
767
- - [ ] WebSocket for real-time output
768
- - [ ] GPU support for ML workloads
769
 
770
  ## License
771
- MIT License - Feel free to use and modify!
772
 
773
- ---
 
 
774
 
775
- **Questions?** Open an issue or discussion on the Space!
 
 
 
1
+ ๏ปฟ---
 
2
  title: Landrun Sandbox + Browser Automation
3
+ emoji: ๐Ÿ”’
 
 
4
  colorFrom: purple
5
+ colorTo: blue
 
 
6
  sdk: docker
7
+ app_file: app.py
 
 
8
  pinned: false
9
+ license: mit
 
 
10
  ---
11
 
12
+ # Landrun Sandbox + Browser Automation
 
 
 
 
13
 
14
  **Kernel-Level Code Execution Sandbox with Automated UI Testing**
15
 
 
 
16
  Execute code with maximum security using **Landrun** (Linux Landlock kernel security) and automatically test UIs with **Playwright** browser automation.
17
 
18
+ ## Features
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
+ ### Landrun Security
21
+ - Kernel-level isolation using Linux Landlock LSM
22
+ - Zero-trust execution with restricted filesystem access
23
+ - Read-only system files - only /tmp/sandbox is writable
24
+ - Network restrictions - only HTTP/HTTPS allowed
25
+ - 10-second timeout protection
26
 
27
+ ### Browser Automation
28
+ - Playwright Chromium for automated UI testing
29
+ - Screenshot capture before/after actions
30
+ - Element interaction - click, type, wait, get text
31
+ - One-shot API - execute code and test UI in single call
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  ### Supported Languages
34
+ - Python 3.11 with stdlib + compilers
35
+ - JavaScript Node.js server-side execution
36
+ - React JSX client-side components with live preview
37
+ - HTML + CSS static pages with full styling
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
+ ## API Endpoints
 
 
 
 
 
40
 
41
+ ### POST /execute
42
+ Execute code in sandbox and get preview URL
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
+ ### GET /preview/{uuid}
45
+ Get live HTML preview of executed code
 
 
46
 
47
+ ### POST /browser/test
48
+ Test existing preview with browser automation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
+ ### POST /browser/execute_and_test
51
+ Execute code and test UI in single call (one-shot)
52
 
53
+ ## Quick Start
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
+ Python example:
56
+ - Execute React code with browser automation
57
+ - Click buttons and capture screenshots
58
+ - Get test results with base64 screenshots
59
 
60
+ ## Security
 
 
 
 
 
61
 
62
+ - Landrun Sandbox: Kernel-level isolation using Linux Landlock
63
+ - Read-only: /usr, /lib, /etc are read-only
64
+ - Writable: Only /tmp/sandbox is writable
65
+ - Network: TCP ports 80, 443 only
66
+ - Timeout: 10 seconds max execution
67
+ - Browser: Headless Chromium with 5s action timeout
68
 
69
+ ## Technology Stack
 
 
 
 
70
 
71
+ - Landrun: Go-based Linux Landlock sandbox
72
+ - FastAPI: Modern async Python web framework
73
+ - Playwright: Browser automation framework
74
+ - Chromium: Headless browser engine
75
+ - Docker: Multi-stage container build
76
+ - Python 3.11: Runtime environment with compilers
77
+ - Node.js: JavaScript execution
78
 
79
+ ## Browser Actions
 
 
 
80
 
81
+ Available actions: click, type, get_text, wait, screenshot
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  ## License
 
84
 
85
+ MIT License
86
+
87
+ ## Links
88
 
89
+ - Live Demo: https://speedofmastery-hmm.hf.space
90
+ - Landrun GitHub: https://github.com/zouuup/landrun
91
+ - Playwright Docs: https://playwright.dev