@stridekit/sandbox
v0.0.3
Published
Client SDK for creating and managing Stridekit sandbox VMs
Downloads
23
Maintainers
Readme
Sandbox SDK
Stridekit Sandbox SDK - Client library for interacting with Stridekit VM Agent via orchestrator.
Installation
npm install @stridekit/sandbox
# or
pnpm add @stridekit/sandboxQuick Start
import { Sandbox } from '@stridekit/sandbox';
// Set API key via environment variable
// export STRIDEKIT_API_KEY="your-api-key"
// Create a new sandbox VM — resolves only once the VM is running
const sandbox = await Sandbox.create();
// Run a command
const result = await sandbox.commands.run({
cmd: 'echo "Hello from Stridekit!"',
});
console.log(result.stdout); // "Hello from Stridekit!"
// Clean up
await sandbox.terminate();Authentication
Generate an API key at app.stridekit.ai/orgs/{your-org}/api-keys.
The SDK supports multiple authentication methods.
Quick Overview
// 1. Environment variable (recommended)
// export STRIDEKIT_API_KEY="your-api-key"
const sandbox = await Sandbox.create();
// 2. Static configuration
Sandbox.config({ apiKey: 'your-api-key' });
// 3. Dynamic resolver
Sandbox.config({
resolveApiKey: async () => await getToken(),
});Usage
Create a sandbox
const sandbox = await Sandbox.create({
vmConfig: {
name: string; // VM name
cpuCount: number; // Number of CPUs
memoryMB: number; // Memory in MB
preset: VmPreset; // 'ubuntu24-x86_64' | 'ubuntu24-aarch64' | 'alpine3-x86_64' | 'alpine3-aarch64'
networkPolicy?: NetworkPolicy; // Egress policy (undefined = deny-all; use 'allow-all' to opt out)
exposedPorts?: ExposedPort[]; // Ports accessible from outside the VM
timeoutSeconds?: number; // Auto-terminate after N seconds (max 18000, default 3600)
volumeMounts?: VolumeMount[]; // Persistent volumes to attach
envVars?: Record<string, string>; // Env vars injected into all commands and PTYs
};
timeout?: number; // Command timeout (ms)
vmCreationTimeout?: number; // VM creation timeout (ms, default 180 000)
});Run a command
const result = await sandbox.commands.run({ cmd: 'node --version' });
console.log(result.stdout); // e.g. "v22.0.0"
console.log(result.exitCode); // 0Snapshot
const snapshot = await Sandbox.createSnapshot({ vmId: sandbox.getVmInfo().vmId, name: 'my-snapshot' });
const restored = await Sandbox.restoreSnapshot({ snapshotId: snapshot.snapshotId });Volume
const volume = await Sandbox.createVolume({ sizeGb: 10 });
const sandbox = await Sandbox.create({
vmConfig: { ..., volumeMounts: [{ volumeId: volume.volumeId, mountPath: '/data' }] },
});Port forwarding (Node.js only)
import { SandboxNode } from '@stridekit/sandbox/node';
const sandbox = await SandboxNode.create();
const fwd = await sandbox.portForward(3000);
console.log(`http://${fwd.host}:${fwd.port}`);
await fwd.close();Documentation
Full API reference, guides, and examples: docs.stridekit.ai
License
Licensed under the Apache License, Version 2.0.
