@computesdk/createos-sandbox

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

CreateOS provider for ComputeSDK — NodeOps VM sandboxes with pause/resume/fork snapshots

原始使用文档
文档目录7 节
  1. Install
  2. Usage
  3. Configuration
  4. Capability mapping
  5. Native escape hatch
  6. Known limitations
  7. License

@computesdk/createos-sandbox

ComputeSDK provider for CreateOS — NodeOps' createos-sandbox VM sandbox service. Thin adapter over the official @nodeops-createos/sandbox.

Install

npm install computesdk @computesdk/createos-sandbox

Usage

import { compute } from "computesdk";
import { createosSandbox } from "@computesdk/createos-sandbox";

compute.setConfig({
  provider: createosSandbox({
    apiKey: process.env.CREATEOS_SANDBOX_API_KEY,
    baseUrl: process.env.CREATEOS_SANDBOX_BASE_URL,
  }),
});

const sandbox = await compute.instances.create({ memoryMb: 1024, image: "devbox:1" });
const { stdout } = await sandbox.runCommand("echo hello");
await sandbox.filesystem.writeFile("/tmp/x.txt", "hi");
await sandbox.destroy();

Configuration

FieldEnv fallbackNotes
apiKeyCREATEOS_SANDBOX_API_KEYRequired. createos-sandbox API key.
baseUrlCREATEOS_SANDBOX_BASE_URLControl-plane URL. Optional; defaults to the production control plane.
shape—Default VM shape (e.g. s-1vcpu-1gb).
rootfs—Default rootfs catalog name / template.
timeout—Reported getInfo().timeout (ms). Informational.

Capability mapping

createos-sandbox sizes VMs from a shape catalog (not free-form cpu/mem), so create() fetches the live catalog (GET /v1/shapes) and maps ComputeSDK's cpus/memoryMb onto the smallest shape that fits. Pass a provider-specific shape to pin one exactly (skips the catalog fetch). With no size pinned, the default is the smallest live shape with ≥1 GiB RAM. image/runtime map to rootfs; ephemeralDiskMb is passed straight through to disk_mib (the control plane validates it; 0/omitted = the shape's default disk).

ComputeSDKcreateos-sandbox
shape selectionGET /v1/shapes (live catalog, nearest fit)
sandbox.create / getById / list / destroyPOST/GET/DELETE /v1/sandboxes
sandbox.runCommandPOST /v1/sandboxes/:id/exec (wrapped in sh -c)
sandbox.getInfoGET /v1/sandboxes/:id
sandbox.getUrl({port})per-sandbox ingress URL
filesystem.readFile / writeFileGET/PUT /v1/sandboxes/:id/files
filesystem.mkdir / readdir / exists / removesynthesised via runCommand
snapshot.create / list / deletepause → fork({ start_paused: true }) → resume / list paused / destroy

Template builds (/v1/templates) are not exposed through the ComputeSDK provider surface — ComputeSDK's public Provider type can't carry the createos-specific dockerfile create option type-safely. Build templates with the native @nodeops-createos/sandbox client (client.templates.create) directly.

Native escape hatch

ComputeSDK's core surface has no pause/resume/fork. Reach the full @nodeops-createos/sandbox Sandbox handle via getInstance():

const native = sandbox.getInstance();
await native.pause();
await native.waitUntilPaused(); // pause() returns while the VM is still "pausing"
const clone = await native.fork();
await native.resume();
await native.attachDisk({ diskId: "my-bucket", mountPath: "/mnt/data" });

Known limitations

  • runCommand env/cwd are synthesised — createos-sandbox drops per-exec env server-side, so env/cwd are injected by wrapping the command in an inline sh -c script. Sandbox-level env should be set at create time (envs).
  • Snapshots are paused forks — createos forks only from a paused sandbox, so snapshot.create briefly pauses the source, forks it into a paused copy (the snapshot, with its own id) and resumes the source. create({ snapshotId }) forks that copy into a fresh sandbox; snapshot.delete destroys it. A snapshot taken while a process is running captures its memory state too.
  • getUrl turns on ingress — sandboxes are created with ingress off (pass ingressEnabled: true to enable it at create); getUrl enables it on demand the first time a URL is requested. Ingress currently serves a non-CA TLS cert and strips the Authorization header upstream — use protocol: "http" / curl -k and don't rely on HTTP auth behind ingress.
  • readdir parses ls output — relies on coreutils ls in the rootfs.

License

MIT

版本与发布记录

@computesdk/createos-sandbox 共发布 27 个版本,首次发布于 2026/07/02;过去 12 个月发布了 27 个版本。

版本发布日期距今
0.1.27latest2026/11/064 天前
0.1.262026/11/046 天前
0.1.252026/10/3110 天前
0.1.242026/10/2812 天前
0.1.232026/10/2714 天前
0.1.222026/10/2317 天前

关于 @computesdk/createos-sandbox 的常见问题

@computesdk/createos-sandbox 是什么?

CreateOS provider for ComputeSDK — NodeOps VM sandboxes with pause/resume/fork snapshots

如何安装 @computesdk/createos-sandbox?

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

@computesdk/createos-sandbox 支持 TypeScript 吗?

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

@computesdk/createos-sandbox 支持 ESM 还是 CommonJS?

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

@computesdk/createos-sandbox 需要什么版本的 Node.js?

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

@computesdk/createos-sandbox 可以商用吗?

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

@computesdk/createos-sandbox 的下载量有多少?

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

@computesdk/createos-sandbox 还在维护吗?

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