@computesdk/mosaic

中文文档
0.1.23发布于 2026/11/06MITTypeScriptESM + CJS近 30 天下载 1.5万

Mosaic provider for ComputeSDK - Firecracker-based sandbox environments

原始使用文档
文档目录7 节
  1. Installation
  2. Quick start
  3. Configuration
  4. Templates, snapshots, and images
  5. Supported operations
  6. Notes
  7. License

@computesdk/mosaic

Mosaic provider for ComputeSDK. Mosaic provides Firecracker-based sandbox environments with command execution, a workspace filesystem, preview URLs, snapshots, and environments built from container images.

Installation

npm install computesdk @computesdk/mosaic

Quick start

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

compute.setConfig({
  provider: mosaic({
    baseUrl: process.env.MOSAIC_API_URL,
    apiKey: process.env.MOSAIC_API_TOKEN,
  }),
});

const sandbox = await compute.instances.create({ templateId: 'node-20' });

await sandbox.filesystem.writeFile('/workspace/server.js', 'require("http").createServer((_, r) => r.end("ok")).listen(3000)');
await sandbox.runCommand('node /workspace/server.js', { background: true });
console.log(await sandbox.getUrl({ port: 3000 }));

await sandbox.destroy();

The provider also reads MOSAIC_API_URL and MOSAIC_API_TOKEN when those values are omitted from the configuration. baseUrl should point to a Mosaic API deployment, and apiKey is sent as a bearer token.

Configuration

interface MosaicConfig {
  baseUrl?: string;
  apiKey?: string;
  template?: string;
  memoryMb?: number;
  vcpu?: number;
  requestTimeoutMs?: number;
  /** Outbound network access. On by default. */
  networkEnabled?: boolean;
  /** Lifetime of a URL from getUrl, in seconds. Defaults to 3600. */
  previewExpiresInSeconds?: number;
}

Per-sandbox templateId, runtime, memoryMb, memoryMiB, vcpus, cpus, and metadata options override the provider defaults.

Templates, snapshots, and images

node-20 and python-3.11 are Mosaic's stock templates. Anything else — a templateId that is not stock, a snapshotId, or an image — is one of your own environments, addressed by id or by the name you gave it:

const provider = mosaic({});

// Build an environment from any linux/amd64 registry image (minutes, once).
await provider.template.create({ name: 'my-env', image: 'python:3.12-slim' });

// Sandboxes from it restore in about a second, like any other template.
const sandbox = await compute.instances.create({ templateId: 'my-env' });

// Or checkpoint a sandbox you have already set up.
const snapshot = await provider.snapshot.create(sandbox.instanceId, { name: 'my-toolchain' });
await compute.instances.create({ snapshotId: 'my-toolchain' });

template.create accepts image plus optional retentionSeconds and registryUsername/registryPassword for a private image. Registry credentials are used for that single pull and are never stored.

Supported operations

MethodSupportedNotes
create✅Stock template, snapshot, or image environment; resource and metadata overrides.
getById✅Returns null when the sandbox is not found.
list✅Lists sandboxes visible to the API token.
destroy✅Idempotent for missing sandboxes.
runCommand✅Working directory, environment, timeout, and background execution.
getInfo✅Returns lifecycle state and resource metadata.
getUrl✅Expiring HTTPS preview URL for a guest port.
filesystem✅Read, write, mkdir, readdir, exists, remove.
snapshot✅Create, list, and delete; a snapshot can be named and restored by name.
template✅Build, list, and delete environments from container images.

Notes

  • background: true launches the command detached through the shell process tier, so a dev server outlives the request that started it and the sandbox can still be paused. The returned stdout is the shell job id.
  • Filesystem calls inside /workspace use Mosaic's binary-safe files API; paths outside it fall back to the shell.
  • Images must be linux/amd64 and contain /bin/sh, so distroless and scratch images are refused.
  • Previews are served over HTTPS by Mosaic's edge; getUrl rejects any other protocol.

License

MIT

版本与发布记录

@computesdk/mosaic 共发布 23 个版本,首次发布于 2026/08/06;过去 12 个月发布了 23 个版本。

版本发布日期距今
0.1.23latest2026/11/064 天前
0.1.222026/11/046 天前
0.1.212026/10/3011 天前
0.1.202026/10/2812 天前
0.1.192026/10/2813 天前
0.1.182026/10/2317 天前

关于 @computesdk/mosaic 的常见问题

@computesdk/mosaic 是什么?

Mosaic provider for ComputeSDK - Firecracker-based sandbox environments

如何安装 @computesdk/mosaic?

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

@computesdk/mosaic 支持 TypeScript 吗?

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

@computesdk/mosaic 支持 ESM 还是 CommonJS?

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

@computesdk/mosaic 可以商用吗?

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

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

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

@computesdk/mosaic 还在维护吗?

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