Examples (JavaScript / TypeScript)
Run AI-generated code
import { Sandbox } from "@sistemo/sdk";
const code = await askTheLLM("write JS that prints fibonacci(30)");
const sb = await Sandbox.create({ stack: "node" });
try {
const r = await sb.run(`node -e ${JSON.stringify(code)}`);
if (r.exitCode === 0) feedBackToLLM(r.stdout);
else feedBackToLLM(`Error:\n${r.stderr}`);
} finally {
await sb.close();
}
Install dependencies, then run
const sb = await Sandbox.create({ stack: "node" });
try {
await sb.run("npm install -g cowsay");
console.log((await sb.run("cowsay hi")).stdout);
} finally {
await sb.close();
}
Write a file, then execute it
const script = "console.log('from a file')";
const sb = await Sandbox.create();
try {
await sb.run(`cat > /tmp/run.js <<'EOF'\n${script}\nEOF`);
console.log((await sb.run("node /tmp/run.js")).stdout);
} finally {
await sb.close();
}
Inspect the environment
const sb = await Sandbox.create();
console.log((await sb.run("uname -a")).stdout);
console.log((await sb.run("cat /etc/os-release")).stdout);
await sb.close();
Point at a self-hosted server
const sb = await Sandbox.create({
baseUrl: "https://your-own-host:8000",
apiKey: "sk_live_your_self_hosted_key",
});