leap0
v0.6.0
Published
TypeScript SDK for the Leap0 API
Maintainers
Readme
Leap0 JS SDK
TypeScript SDK for Leap0, enterprise-grade cloud sandboxes for AI agents.
Launch isolated sandboxes in milliseconds. Give each agent its own compute, filesystem, and network boundary while keeping a simple typed Node.js API.
Installation
This SDK is Node.js-only and requires Node.js 20.6.0 or newer.
npm install leap0Requirements
- Node.js 20.6.0+
- A Leap0 API key
Getting an API key
- Sign up at app.leap0.dev.
- Copy your API key from the dashboard.
- Set it as an environment variable:
export LEAP0_API_KEY="your-api-key"Or pass it directly when creating a client:
import { Leap0Client } from "leap0";
const client = new Leap0Client({ apiKey: "your-api-key" });Quick Start
import { Leap0Client } from "leap0";
const client = new Leap0Client();
const sandbox = await client.sandboxes.create();
try {
const result = await sandbox.process.execute({ command: "echo hello from leap0" });
console.log(result.exitCode);
console.log(result.stdout.trim());
console.log(result.stderr.trim());
} finally {
await sandbox.delete();
await client.close();
}Features
Code Interpreter
Stateful code execution with streaming output.
import { CodeLanguage, DEFAULT_CODE_INTERPRETER_TEMPLATE_NAME } from "leap0";
const sandbox = await client.sandboxes.create({
templateName: DEFAULT_CODE_INTERPRETER_TEMPLATE_NAME,
});
const result = await sandbox.codeInterpreter.execute({
code: "x = 42",
language: CodeLanguage.PYTHON,
});Filesystem
Read, write, search, and inspect files inside a sandbox.
await sandbox.filesystem.writeFile("/workspace/hello.txt", "Hello!");
const content = await sandbox.filesystem.readFile("/workspace/hello.txt");
const tree = await sandbox.filesystem.tree("/workspace", 2);Git
Clone repositories and run Git operations inside the sandbox.
await sandbox.git.clone("https://github.com/octocat/Hello-World.git", "/workspace/repo");
const status = await sandbox.git.status("/workspace/repo");Process Execution
Run one-off shell commands inside a running sandbox.
const result = await sandbox.process.execute({ command: "ls -la /workspace" });
console.log(result.stdout);
console.log(result.stderr);
const withEnv = await sandbox.process.execute({
command: "printenv NAME",
cwd: "/workspace/app",
env: { NAME: "leap0", PLACE: "sandbox" },
});Interactive Terminal (PTY)
Open persistent terminal sessions over WebSocket.
const session = await sandbox.pty.create({ cols: 120, rows: 30, cwd: "/home/user" });Language Server Protocol (LSP)
Use language servers for completions and editor-style workflows.
await sandbox.lsp.start({ languageId: "python", pathToProject: "/workspace" });SSH Access
Generate temporary SSH credentials for direct sandbox access.
const access = await sandbox.ssh.createAccess();
console.log(access.hostname, access.port, access.username);Presigned URLs
Create a temporary public URL for a sandbox port. expiresIn is in seconds.
const presigned = await sandbox.createPresignedUrl({ port: 8080, expiresIn: 900 }); // 15 minutes
console.log(presigned.url);
await sandbox.deletePresignedUrl(presigned.id);Desktop Automation
Control a graphical desktop inside the sandbox.
const screenshot = await sandbox.desktop.screenshot();Snapshots
Save and restore sandbox state.
const snapshot = await client.snapshots.create(sandbox, { name: "my-checkpoint" });
const restored = await client.snapshots.resume({ snapshotName: snapshot.name ?? "my-checkpoint" });Supported Imports
Import clients, enums, and types from the package root:
import { Leap0Client, SandboxState, type CreateSandboxParams } from "leap0";Examples
See examples/ for end-to-end usage patterns:
quickstart.ts- Basic code executioncode_interpreter_stream.ts- Streaming code execution outputfilesystem_and_git.ts- File and Git operationspty.ts- Interactive terminal sessiondesktop.ts- Desktop GUI automationsnapshots.ts- Save and restore sandbox statessh.ts- Generate and validate SSH access
Runtime Support
- Node.js 20.6.0+
- ESM package (
"type": "module") - Uses Node-specific APIs including
process.env, OpenTelemetry Node providers, andUser-Agentrequest headers
Documentation
Full documentation is available at leap0.dev/docs.
License
Apache License 2.0. See LICENSE for details.
