@computesdk/tensorlake

中文文档
0.1.34发布于 2026/11/06MITTypeScriptESM + CJS构建来源已验证近 30 天下载 1.1万

Tensorlake provider for ComputeSDK - stateful MicroVM sandboxes for agentic applications and LLM-generated code execution

原始使用文档
文档目录22 节
  1. Installation
  2. Setup
  3. Quick Start
  4. Gateway Mode (Recommended)
  5. Direct Mode
  6. Configuration
  7. Environment Variables
  8. Configuration Options
  9. Features
  10. API Reference
  11. Sandbox Management
  12. Command Execution
  13. Filesystem Operations
  14. Snapshots
  15. URL Access
  16. Examples
  17. Agentic Code Execution
  18. Snapshot-Backed Warm Starts
  19. Error Handling
  20. Best Practices
  21. Support
  22. License

@computesdk/tensorlake

Tensorlake provider for ComputeSDK - stateful MicroVM sandboxes for agentic applications and LLM-generated code execution.

Installation

npm install @computesdk/tensorlake

Setup

  1. Get your API key from cloud.tensorlake.ai
  2. Set the environment variable:
export TENSORLAKE_API_KEY=your_api_key_here

Quick Start

Use the gateway for zero-config auto-detection:

import { compute } from 'computesdk';

// Auto-detects Tensorlake from TENSORLAKE_API_KEY environment variable
const sandbox = await compute.instances.create();

const result = await sandbox.runCommand('uname -a');
console.log(result.stdout);

await sandbox.destroy();

Direct Mode

For direct SDK usage without the gateway:

import { tensorlake } from '@computesdk/tensorlake';

const compute = tensorlake({ apiKey: process.env.TENSORLAKE_API_KEY });

const sandbox = await compute.instances.create();

const result = await sandbox.runCommand(`uname -a`);

console.log(result.stdout);
await sandbox.destroy();

Configuration

Environment Variables

export TENSORLAKE_API_KEY=your_api_key_here
export TENSORLAKE_API_URL=https://api.tensorlake.ai   # optional override

Configuration Options

interface TensorlakeConfig {
  /** Tensorlake API key — falls back to TENSORLAKE_API_KEY environment variable */
  apiKey?: string;
  /** Override for the management API base URL */
  apiUrl?: string;
  /** Override for the sandbox proxy URL */
  proxyUrl?: string;
  /** Default container image for new sandboxes (default: ubuntu-minimal) */
  image?: string;
  /** Default timeout in seconds for sandboxes */
  timeout?: number;
}

Features

  • Stateful MicroVMs - Full VM isolation with persistent state within a session
  • Snapshot & restore - Snapshot a running sandbox and resume from it later
  • Code execution - Python and Node.js with auto-detection
  • Command execution - Run shell commands, including background processes
  • Filesystem operations - Read, write, list, and remove files and directories
  • URL access - Expose sandbox ports via proxy URLs
  • Auto runtime detection - Automatically detects Python vs Node.js from code patterns

API Reference

Sandbox Management

// Create a sandbox (default image: ubuntu-minimal)
const sandbox = await compute.instances.create();

// Create with options
const sandbox = await compute.instances.create({
  image: 'ubuntu-minimal',
  timeout: 300000,         // ms → converted to seconds internally
  name: 'my-sandbox',
  snapshotId: 'snap-abc123', // resume from a snapshot
});

// Get an existing sandbox by ID
const sandbox = await compute.instances.getById('sandbox-id');

// List all running sandboxes
const sandboxes = await compute.instances.list();

// Destroy a sandbox
await sandbox.destroy();

Command Execution

// Run a command and wait for output
const result = await sandbox.runCommand('ls -la /tmp');
console.log(result.stdout);
console.log(result.exitCode);

// Run with environment variables and working directory
const result = await sandbox.runCommand('npm install', {
  env: { NODE_ENV: 'production' },
  cwd: '/app',
});

// Fire-and-forget background process
await sandbox.runCommand('python server.py', { background: true });

Filesystem Operations

// Write a file
await sandbox.filesystem.writeFile('/tmp/hello.py', 'print("Hello")');

// Read a file
const content = await sandbox.filesystem.readFile('/tmp/hello.py');

// Create a directory (creates parents as needed)
await sandbox.filesystem.mkdir('/tmp/data/nested');

// List directory contents
const entries = await sandbox.filesystem.readdir('/tmp');
// entries: [{ name, type: 'file'|'directory', size, modified }]

// Check existence
const exists = await sandbox.filesystem.exists('/tmp/hello.py');

// Remove a file or directory
await sandbox.filesystem.remove('/tmp/hello.py');

Snapshots

// Snapshot the current state of a running sandbox
const snapshot = await compute.snapshot.create(instanceId, { name: 'after-setup' });
console.log(snapshot.id); // 'snap-abc123'

// List all snapshots
const snapshots = await compute.snapshot.list();

// Delete a snapshot
await compute.snapshot.delete('snap-abc123');

// Resume from a snapshot
const sandbox = await compute.instances.create({ snapshotId: 'snap-abc123' });

URL Access

// Get a proxy URL for a port exposed inside the sandbox
const url = await sandbox.getUrl({ port: 443 });
// → "https://<sandbox-id>.sandbox.tensorlake.ai"

const customPortUrl = await sandbox.getUrl({ port: 8080 });
// → "https://8080-<sandbox-id>.sandbox.tensorlake.ai"

const wsUrl = await sandbox.getUrl({ port: 443, protocol: 'wss' });
// → "wss://<sandbox-id>.sandbox.tensorlake.ai"

getUrl registers the port in the sandbox's exposed_ports and enables unauthenticated access, so the returned URL is publicly reachable — treat it as a public endpoint.

Examples

Agentic Code Execution

import { tensorlake } from '@computesdk/tensorlake';

const compute = tensorlake({ apiKey: process.env.TENSORLAKE_API_KEY });
const sandbox = await compute.instances.create({ timeout: 600000 });

// Install dependencies once
await sandbox.runCommand('pip install requests pandas');

const result = await sandbox.runCommand('python --version');
console.log(result.stdout);

await sandbox.destroy();

Snapshot-Backed Warm Starts

import { tensorlake } from '@computesdk/tensorlake';

const compute = tensorlake({ apiKey: process.env.TENSORLAKE_API_KEY });

// One-time setup: create a pre-warmed snapshot
async function createBaseSnapshot(): Promise<string> {
  const sandbox = await compute.instances.create();
  await sandbox.runCommand('pip install pandas numpy scikit-learn');
  const snapshot = await compute.snapshot.create(sandbox.instanceId);
  await sandbox.destroy();
  return snapshot.id;
}

// Fast boot from snapshot — skips install step
const snapshotId = await createBaseSnapshot();
const sandbox = await compute.instances.create({ snapshotId });

const result = await sandbox.runCommand(`uname -a`);

console.log(result.stdout);
await sandbox.destroy();

Error Handling

import { tensorlake } from '@computesdk/tensorlake';

try {
  const compute = tensorlake({ apiKey: process.env.TENSORLAKE_API_KEY });
  const sandbox = await compute.instances.create();
  const result = await sandbox.runCommand('umane -a');
  console.log(result.stdout);
} catch (error) {
  if (error.message.includes('Missing Tensorlake API key')) {
    console.error('Set TENSORLAKE_API_KEY environment variable');
  } else if (error.message.includes('authentication failed')) {
    console.error('Check your API key at https://cloud.tensorlake.ai');
  } else {
    console.error(error);
  }
}

Best Practices

  1. Snapshots for warm starts - Snapshot after installing dependencies to avoid repeating setup
  2. Destroy sandboxes - Always call sandbox.destroy() to release resources
  3. Set timeouts - Use timeout on long-running workloads to avoid runaway VMs
  4. Background processes - Use { background: true } for servers or daemons; they survive after the initiating command returns
  5. API key security - Never commit API keys; use environment variables or a secrets manager

Support

License

MIT

版本与发布记录

@computesdk/tensorlake 共发布 36 个版本,首次发布于 2026/05/06;过去 12 个月发布了 36 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.34latest2026/11/064 天前
0.1.332026/11/046 天前
0.1.322026/10/2812 天前
0.1.312026/10/2813 天前
0.1.302026/10/2714 天前
0.1.292026/10/2714 天前

关于 @computesdk/tensorlake 的常见问题

@computesdk/tensorlake 是什么?

Tensorlake provider for ComputeSDK - stateful MicroVM sandboxes for agentic applications and LLM-generated code execution

如何安装 @computesdk/tensorlake?

在项目目录运行 npm install @computesdk/tensorlake,或使用 pnpm add / yarn add / bun add。

@computesdk/tensorlake 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@computesdk/tensorlake 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@computesdk/tensorlake 可以商用吗?

@computesdk/tensorlake 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@computesdk/tensorlake 的下载量有多少?

根据 npm 官方下载统计,@computesdk/tensorlake 在 2026/10/11 – 2026/11/09 这 30 天内被下载 10,607 次,日均约 354 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@computesdk/tensorlake 还在维护吗?

最新版本 0.1.34 发布于 2026/11/06(4 天前);至今共发布 36 个版本,其中过去 12 个月发布了 36 个;首次发布于 2026/05/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。