Run data transformations, analysis scripts, and report generation in isolated containers
Use isol8 to run untrusted or user-provided data processing scripts safely. This is common in platforms where users upload data and define custom transformations, or where you need to run third-party analysis scripts without risking the host.
For complex pipelines, inject input files and retrieve output files:
Copy
const isol8 = new DockerIsol8({ mode: "persistent" });await isol8.start();// Step 1: Upload raw dataawait isol8.putFile("/sandbox/raw.json", JSON.stringify(rawData));// Step 2: Run cleaning scriptawait isol8.execute({ code: `import jsonwith open("/sandbox/raw.json") as f: data = json.load(f)# Remove nulls, normalize stringscleaned = [ {k: v.strip() if isinstance(v, str) else v for k, v in row.items()} for row in data if all(v is not None for v in row.values())]with open("/sandbox/cleaned.json", "w") as f: json.dump(cleaned, f)print(f"Cleaned {len(data)} -> {len(cleaned)} records")`, runtime: "python",});// Step 3: Run analysis scriptawait isol8.execute({ code: `import jsonwith open("/sandbox/cleaned.json") as f: data = json.load(f)# Compute statisticsstats = { "count": len(data), "fields": list(data[0].keys()) if data else [],}with open("/sandbox/report.json", "w") as f: json.dump(stats, f, indent=2)print("Report generated")`, runtime: "python",});// Step 4: Retrieve the reportconst report = await isol8.getFile("/sandbox/report.json");console.log(report.toString());await isol8.stop();
Generate plots with matplotlib and retrieve the image:
Copy
const result = await isol8.execute({ code: `import matplotlibmatplotlib.use('Agg') # Non-interactive backendimport matplotlib.pyplot as pltimport jsonwith open("/sandbox/data.json") as f: data = json.load(f)categories = [d["category"] for d in data]values = [d["value"] for d in data]plt.figure(figsize=(10, 6))plt.bar(categories, values, color='#0E7C6B')plt.title("Sales by Category")plt.ylabel("Revenue ($)")plt.tight_layout()plt.savefig("/sandbox/chart.png", dpi=150)print("Chart saved")`, runtime: "python", installPackages: ["matplotlib"], files: { "/sandbox/data.json": JSON.stringify(chartData), }, outputPaths: ["/sandbox/chart.png"],});// result.files["/sandbox/chart.png"] contains the PNG as base64const chartBase64 = result.files?.["/sandbox/chart.png"];