@computesdk/run-cloud

中文文档
1.0.19发布于 2026/11/06MITTypeScriptESM + CJS近 30 天下载 9029

Run Cloud provider for ComputeSDK - fast Firecracker microVM sandboxes with snapshots and filesystem access

原始使用文档
文档目录4 节
  1. Installation
  2. Usage
  3. Configuration
  4. Supported Operations

@computesdk/run-cloud

Run Cloud provider for ComputeSDK. Run commands inside fast Firecracker microVM sandboxes with configurable CPU, memory, and disk, native file reads, snapshots, and automatic idle pause.

Installation

npm install computesdk @computesdk/run-cloud

Create an API key in the Run Cloud dashboard and export it:

export RUN_CLOUD_API_KEY=rc_live_your_key

RUN_CLOUD_API_TOKEN is supported as a backwards-compatible alias. Set RUN_CLOUD_API_URL only when targeting a custom Run Cloud deployment.

Usage

import { compute } from 'computesdk';
import { runCloud } from '@computesdk/run-cloud';

compute.setConfig({
  provider: runCloud({
    apiKey: process.env.RUN_CLOUD_API_KEY,
    cpu: 2,
    memory: 4096,
    disk: 40,
  }),
});

const sandbox = await compute.instances.create({
  templateId: 'runcloud/agent-base',
  name: 'agent-task',
});

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

await sandbox.filesystem.writeFile('/tmp/result.txt', result.stdout);
console.log(await sandbox.filesystem.readFile('/tmp/result.txt'));

const snapshot = await compute.snapshot.create(sandbox.instanceId, {
  name: 'after-setup',
});

await sandbox.destroy();

const restored = await compute.instances.create({
  snapshotId: snapshot.id,
  name: 'restored-task',
});

The provider factory can also be used directly:

const cloud = runCloud({ apiKey: process.env.RUN_CLOUD_API_KEY });
const sandbox = await cloud.sandbox.create({ cpu: 1, memory: 1024 });

Configuration

interface RunCloudConfig {
  apiKey?: string;
  apiUrl?: string;
  fetch?: typeof fetch;
  image?: string;
  cpu?: number;
  memory?: number;
  disk?: number;
  idlePauseSeconds?: number;
  timeout?: number;
  region?: string;
  orgId?: string;
  commandTimeout?: number;
  tunnelTtlSeconds?: number;
}
  • cpu accepts fractional vCPU values.
  • memory is measured in MiB.
  • disk is the writable disk quota in GiB.
  • timeout and commandTimeout are milliseconds.
  • tunnelTtlSeconds controls public port URL lifetime and defaults to one hour.
  • idlePauseSeconds is seconds; set it to 0 to disable automatic pause.
  • templateId and image both select a registered Run Cloud OCI image.
  • snapshotId restores a previously created Run Cloud snapshot.
  • Fresh creates accept per-create cpu, memory, disk, idlePauseSeconds, timeoutSeconds, region, name, orgId, and idempotencyKey overrides.
  • Snapshot restores accept cpu, memory, disk, timeoutSeconds, region, and name overrides. Options the restore API cannot apply are rejected instead of being silently ignored.

Run Cloud does not currently support persistent sandbox-level envs. Pass command-scoped variables with:

await sandbox.runCommand('echo "$MODEL"', {
  env: { MODEL: 'gpt-5' },
});

Supported Operations

MethodSupportedNotes
create✅Fresh image boot or snapshot restore; restore-safe overrides are validated and applied.
getById✅Returns null when the sandbox does not exist.
list✅Lists running sandboxes visible to the API key.
destroy✅Idempotent when the sandbox is already gone.
runCommand✅Supports cwd, command-scoped env, timeouts, streaming callbacks, and detached background commands.
getInfo✅Refreshes state and resource metadata from Run Cloud.
getUrl✅Opens an expiring capability URL without making the sandbox persistent.
Filesystem✅Native reads; shell-backed write, mkdir, list, exists, and remove.
Snapshots✅Create, list, delete, and restore through snapshotId.

sandbox.getInstance() returns a RunCloudSandbox handle containing the official Client and the latest native sandbox record.

Tunnel hostnames are random bearer capabilities. Do not write them to public logs. They expire automatically and are removed when the tunnel or sandbox is deleted.

版本与发布记录

@computesdk/run-cloud 共发布 19 个版本,首次发布于 2026/08/11;过去 12 个月发布了 19 个版本。

版本发布日期距今
1.0.19latest2026/11/064 天前
1.0.182026/11/046 天前
1.0.172026/10/2812 天前
1.0.162026/10/2317 天前
1.0.152026/10/2318 天前
1.0.142026/10/2218 天前

关于 @computesdk/run-cloud 的常见问题

@computesdk/run-cloud 是什么?

Run Cloud provider for ComputeSDK - fast Firecracker microVM sandboxes with snapshots and filesystem access

如何安装 @computesdk/run-cloud?

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

@computesdk/run-cloud 支持 TypeScript 吗?

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

@computesdk/run-cloud 支持 ESM 还是 CommonJS?

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

@computesdk/run-cloud 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@computesdk/run-cloud 可以商用吗?

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

@computesdk/run-cloud 的下载量有多少?

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

@computesdk/run-cloud 还在维护吗?

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