Skip to content

Instantly share code, notes, and snippets.

@romanlv
Created March 22, 2026 03:08
Show Gist options
  • Select an option

  • Save romanlv/60049fe29148be14c121baf5ccaa8577 to your computer and use it in GitHub Desktop.

Select an option

Save romanlv/60049fe29148be14c121baf5ccaa8577 to your computer and use it in GitHub Desktop.
Leap0 code-interpreter API test — endpoints return 404 with system/code-interpreter:v0.1.0 template
export const API_URL = "https://api.leap0.dev";
export const SANDBOX_DOMAIN = "sandbox.leap0.dev";
export const API_KEY = Bun.env.LEAP0_API_KEY ?? "";
if (!API_KEY) {
console.error("LEAP0_API_KEY not set");
process.exit(1);
}
export const headers = {
authorization: API_KEY,
"Content-Type": "application/json",
};
import { API_URL, headers, API_KEY } from "./config";
// Create or reuse sandbox
let sandboxId = "";
const idFile = Bun.file(".sandbox-id");
if (await idFile.exists()) {
sandboxId = (await idFile.text()).trim();
const check = await fetch(`${API_URL}/v1/sandbox/${sandboxId}`, {
headers: { authorization: API_KEY },
});
if (check.status !== 200) sandboxId = "";
}
if (!sandboxId) {
console.log("Creating sandbox...");
const res = await fetch(`${API_URL}/v1/sandbox`, {
method: "POST",
headers,
body: JSON.stringify({
template_name: "system/code-interpreter:v0.1.0",
vcpu: 2,
memory_mib: 2048,
timeout_min: 10,
}),
});
const data = await res.json();
sandboxId = data.id;
await Bun.write(".sandbox-id", sandboxId);
console.log("Created:", sandboxId);
console.log("Waiting for boot...");
await new Promise(r => setTimeout(r, 3000));
} else {
console.log("Reusing sandbox:", sandboxId);
}
console.log("Template: system/code-interpreter:v0.1.0\n");
// Test all code-interpreter endpoints
const tests = [
{ method: "POST", path: `/v1/sandbox/${sandboxId}/code-interpreter/contexts`, body: { language: "python", cwd: "/home/user" } },
{ method: "GET", path: `/v1/sandbox/${sandboxId}/code-interpreter/contexts`, body: null },
{ method: "POST", path: `/v1/sandbox/${sandboxId}/code-interpreter/execute`, body: { code: "print(1)", language: "python" } },
{ method: "POST", path: `/v1/sandbox/${sandboxId}/code-interpreter/execute/async`, body: { code: "print(1)", language: "python" } },
];
for (const t of tests) {
const res = await fetch(`${API_URL}${t.path}`, {
method: t.method,
headers,
...(t.body ? { body: JSON.stringify(t.body) } : {}),
});
const text = await res.text();
console.log(`${t.method} ${t.path} → ${res.status} ${text.slice(0, 200)}`);
}
// Confirm process/execute works for comparison
const proc = await fetch(`${API_URL}/v1/sandbox/${sandboxId}/process/execute`, {
method: "POST",
headers,
body: JSON.stringify({ command: "echo works", cwd: "/", timeout: 5 }),
});
console.log("\nprocess/execute →", proc.status, (await proc.json()).result.trim());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment