@computesdk/superserve

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

Superserve provides sandbox infrastructure to run code in isolated cloud environments powered by Firecracker MicroVMs

原始使用文档
文档目录18 节
  1. Installation
  2. Setup
  3. Quick Start
  4. Configuration
  5. Features
  6. API Reference
  7. sandbox.create(options?)
  8. sandbox.runCommand(command, options?)
  9. sandbox.getUrl({ port })
  10. sandbox.filesystem
  11. sandbox.getInfo() / sandbox.destroy()
  12. provider.sandbox.list() and getById(id)
  13. Templates
  14. Snapshots
  15. Error Handling
  16. Examples
  17. Learn more
  18. License

@computesdk/superserve

Superserve provides sandbox infrastructure to run code in isolated cloud environments powered by Firecracker MicroVMs.

Installation

npm install computesdk @computesdk/superserve

Setup

  1. Get your Superserve API key from console.superserve.ai.
  2. Set the environment variable:
export SUPERSERVE_API_KEY=your_api_key_here

Quick Start

import { compute } from 'computesdk';
import { superserve } from '@computesdk/superserve';

compute.setConfig({
  provider: superserve({ apiKey: process.env.SUPERSERVE_API_KEY }),
});

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

const result = await sandbox.runCommand('node -v');
console.log(result.stdout);

await sandbox.destroy();

Or call the provider factory directly:

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

const provider = superserve({ apiKey: process.env.SUPERSERVE_API_KEY });
const sandbox = await provider.sandbox.create();

Configuration

superserve({
  apiKey: string,      // optional, falls back to SUPERSERVE_API_KEY
  baseUrl: string,     // optional, falls back to SUPERSERVE_BASE_URL,
                       //   then the @superserve/sdk default
  timeout: number,     // optional default auto-pause timeout (ms)
})

Features

FeatureSupported
Sandbox lifecycle (create / connect / list / destroy)✅
Command execution with cwd, env, and timeout✅
Live command output (onStdout / onStderr)✅
Filesystem (read, write, mkdir, readdir, exists, remove)✅
Templates (boot from named template)✅
Snapshots (create, list, delete, boot from snapshot)✅
Preview URLs (getUrl)✅
Pause / resume (memory, processes and files preserved)✅ instance.pause() / instance.resume()
Template build (template.create)❌ Use @superserve/sdk Template.create

API Reference

sandbox.create(options?)

Boots a new microVM. Common options:

await compute.instances.create({
  templateId: 'superserve/python-3.11',    // optional, defaults to superserve/base
  timeout: 60_000,                          // auto-pause timeout in ms
  envs: { API_KEY: 'value' },
  name: 'my-sandbox',
  metadata: { source: 'ci' },
});

Curated templates include superserve/base, superserve/python-3.11, superserve/node-22, and others — see the Superserve docs for the full list.

Pass snapshotId instead of templateId to boot from a snapshot (see Snapshots).

sandbox.runCommand(command, options?)

const result = await sandbox.runCommand('npm install', {
  cwd: '/app',
  env: { NODE_ENV: 'production' },
  timeout: 120_000,
});

console.log(result.exitCode);
console.log(result.stdout);
console.log(result.stderr);

Pass onStdout / onStderr to receive output while the command runs:

await sandbox.runCommand('npm test', {
  onStdout: (data) => process.stdout.write(data),
  onStderr: (data) => process.stderr.write(data),
});

sandbox.getUrl({ port })

await sandbox.runCommand('python3 -m http.server 8000', { background: true });
const url = await sandbox.getUrl({ port: 8000 });

getUrl publishes the port and returns its preview URL. Published ports are public by default. Ports must be between 1024 and 65535; port 49983 is reserved. For private previews and access tokens, use the preview API on sandbox.getInstance() — see the preview URL guide.

sandbox.filesystem

await sandbox.filesystem.writeFile('/app/config.json', '{"key":"value"}');
const text = await sandbox.filesystem.readFile('/app/config.json');
await sandbox.filesystem.mkdir('/app/data');
const entries = await sandbox.filesystem.readdir('/app');
const present = await sandbox.filesystem.exists('/app/config.json');
await sandbox.filesystem.remove('/app/config.json');

readFile and writeFile go directly to the per-sandbox data plane. mkdir, readdir, exists, and remove are implemented via shell commands run through sandbox.runCommand.

sandbox.getInfo() / sandbox.destroy()

const info = await sandbox.getInfo();
console.log(info.id, info.status);

await sandbox.destroy();

Status mapping: Superserve's paused and deleted states are reported as ComputeSDK's stopped, failed as error, and every other state as running.

provider.sandbox.list() and getById(id)

const items = await provider.sandbox.list();      // read-only, no side effects
const sandbox = await provider.sandbox.getById(items[0].instanceId);

list() is read-only — it returns InstanceInfo stubs without opening a session. To actually operate on a listed entry, call getById(id).

Note that getById() issues POST /activate on the sandbox, which auto-resumes paused sandboxes and rotates their access token. If you only need read-only metadata, prefer iterating the result of list() directly.

Templates

const templates = await provider.template!.list();

To create a template, use @superserve/sdk directly — templates require a build spec (from + steps), which the ComputeSDK template.create({ name }) shape doesn't carry.

Snapshots

const snapshot = await provider.snapshot!.create(sandbox.instanceId, {
  name: 'before-upgrade',
});

// Boot a new sandbox from it; processes that were running continue.
const fork = await provider.sandbox.create({ snapshotId: snapshot.id });

const snapshots = await provider.snapshot!.list({ instanceId: sandbox.instanceId });
await provider.snapshot!.delete(snapshot.id);

A snapshot saves a sandbox's memory and disk and is kept until deleted, even after the original sandbox is gone. Snapshots are listed per sandbox: pass instanceId to list(), which returns an empty list without it. snapshot.create() connects to the sandbox first, which resumes it if it is paused. See the snapshots guide.

Error Handling

Common errors and how to recover:

try {
  const sandbox = await compute.instances.create();
} catch (error) {
  const msg = error instanceof Error ? error.message : String(error);

  if (msg.includes('authentication')) {
    // Bad or missing SUPERSERVE_API_KEY
  } else if (msg.includes('quota') || msg.includes('limit')) {
    // Team has hit its concurrent-sandbox cap
  } else {
    // Network or transient platform error — safe to retry with backoff
  }
}

Authentication failures are normalized into a single user-facing message regardless of underlying cause (HTTP 401, missing key, AuthenticationError from the SDK).

Examples

A runnable example lives in examples/basic:

cd examples/basic
export SUPERSERVE_API_KEY=your_key
pnpm superserve

Learn more

License

MIT

版本与发布记录

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

版本发布日期距今
0.2.20latest2026/11/064 天前
0.2.192026/11/046 天前
0.2.182026/10/2812 天前
0.2.172026/10/2318 天前
0.2.162026/10/2318 天前
0.2.152026/10/2218 天前

关于 @computesdk/superserve 的常见问题

@computesdk/superserve 是什么?

Superserve provides sandbox infrastructure to run code in isolated cloud environments powered by Firecracker MicroVMs

如何安装 @computesdk/superserve?

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

@computesdk/superserve 支持 TypeScript 吗?

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

@computesdk/superserve 支持 ESM 还是 CommonJS?

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

@computesdk/superserve 可以商用吗?

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

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

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

@computesdk/superserve 还在维护吗?

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