Getting Started
Install, create a sandbox, run code, and verify health in minutes.
1. Install
1npm i unikernel-sandbox2. Create Sandbox and Execute Code
1import { UnikernelsClient } from "unikernel-sandbox";
2
3const client = new UnikernelsClient();
4const sandbox = await client.createSandbox();
5
6const result = await sandbox.execute({
7 language: "python",
8 code: "print('hello from sandbox')",
9 timeout_ms: 5000,
10});
11
12console.log(result.status);
13console.log(result.stdout);
14
15await sandbox.delete();3. Run a More Complex Workload
1import { UnikernelsClient } from "unikernel-sandbox";
2
3const client = new UnikernelsClient();
4const sandbox = await client.createSandbox();
5
6const result = await sandbox.execute({
7 language: "nodejs",
8 timeout_ms: 7000,
9 code: "const crypto = require('crypto');\nconst words = ['unikernel', 'sandbox', 'ephemeral', 'orchestrator', 'runtime', 'cloud'];\nconst edges = [[0,1],[0,2],[1,3],[2,3],[3,4],[4,5]];\nconst indeg = Array(words.length).fill(0);\nconst g = Array.from({ length: words.length }, () => []);\nfor (const [u, v] of edges) { g[u].push(v); indeg[v]++; }\nconst q = [];\nindeg.forEach((d, i) => { if (d === 0) q.push(i); });\nconst order = [];\nwhile (q.length) {\n const u = q.shift();\n order.push(words[u]);\n for (const v of g[u]) if (--indeg[v] === 0) q.push(v);\n}\nconst digest = crypto.createHash('sha256').update(order.join('->')).digest('hex').slice(0, 24);\nconsole.log(JSON.stringify({ order, digest }));",
10});
11
12console.log(result.stdout);
13await sandbox.delete();4. Verify Service Health
1curl -sS https://sandbox.unikernel.ai/healthz