@computesdk/miosa

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

MIOSA provider for ComputeSDK - hardware-isolated Firecracker microVM sandboxes with snapshots, persistent graduation, and white-label infrastructure

原始使用文档
文档目录8 节
  1. Install
  2. Usage
  3. Configuration
  4. Regional endpoint
  5. Lazy create
  6. Method → endpoint mapping
  7. Testing
  8. License

@computesdk/miosa

MIOSA provider for ComputeSDK with Firecracker microVM sandboxes on the MIOSA cloud.

MIOSA sandboxes can graduate to persistent desktops, serve public preview URLs on custom domains, and use off-host backups through a white-label control plane.

Install

pnpm add @computesdk/miosa computesdk

Usage

import { createCompute } from 'computesdk';
import { miosa } from '@computesdk/miosa';

const compute = createCompute({
  defaultProvider: miosa({ apiKey: process.env.MIOSA_API_KEY }),
});

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

const result = await sandbox.runCommand('python3 -c "print(40 + 2)"');
console.log(result.stdout); // "42"

await sandbox.filesystem.writeFile('/workspace/app.js', 'console.log("hi")');
const url = await sandbox.getUrl({ port: 3000 }); // white-label-aware preview URL

await sandbox.destroy();

Configuration

miosa({
  apiKey: 'msk_…',                       // or MIOSA_API_KEY env var
  baseUrl: 'https://api.miosa.ai/api/v1', // default; point at your white-label control plane
  timeout: 300_000,                       // default sandbox lifetime (ms)
  runnerMode: true,                       // default; false (or MIOSA_RUNNER_MODE=0) keeps create/exec/destroy on the account API
  lazyCreate: false,                      // default; true (or MIOSA_LAZY_CREATE=1) defers create() to first use
});

Auth is a MIOSA API key (msk_*) sent as Authorization: Bearer <key>.

Regional endpoint

Create, exec and destroy go to MIOSA's regional sandbox endpoint (run-<region>.miosa.ai) instead of the account API, which removes a hop from each call. Everything else (list, getById, getUrl, filesystem, snapshots) stays on the account API.

  • With a custom baseUrl (or MIOSA_BASE_URL) the regional endpoint is off by default, so a white-label or self-hosted control plane's key is never sent to MIOSA's public regional host. Set runnerMode: true, MIOSA_RUNNER_MODE=1 or a runnerBaseDomain to opt in.
  • A create the regional endpoint does not serve, such as a template, a snapshot or a shape above the standard size, goes to the account API and the sandbox stays there for its whole life.
  • A create is moved to the account API only when the regional endpoint refused it before provisioning anything: it could not be reached, had no capacity, or did not know the key yet. A timeout or a reset connection is surfaced as an error instead of being sent to the account API, because the request may have been delivered and a second create could provision a second sandbox.

Lazy create

With lazyCreate on, create() makes no network call. The first runCommand() sends one request that creates the sandbox and runs the command. Any other first call (getInfo, getUrl, a filesystem call, getById, a snapshot) creates the sandbox first. Errors from the create surface on that first call. A first command the runner refuses (empty, too large, bad timeout) is reported as a failed command with exit code 127, creates nothing, and leaves the handle unused. A first command that runs but produces no result (deadline, spawn failure) is reported the same way and is not run again. Destroying a handle that was never used sends nothing.

sandboxId is a client-side placeholder for the whole life of the handle, before and after the sandbox exists, because the framework fixes it when create() returns. It names the sandbox only inside the process that created it and is only honoured for the API key that created it. To store or pass the sandbox on, read the real id from getInfo().id. The option only applies while the regional endpoint is in use.

Method → endpoint mapping

ComputeSDK methodMIOSA endpointNotes
sandbox.create()POST /sandboxesWaits server-side until the sandbox is command-ready and returns a compact response; templateId → template_id, snapshotId → snapshot_id, envs → env, timeout(ms) → timeout_sec
sandbox.getById()GET /sandboxes/:id404 → null
sandbox.list()GET /sandboxes
sandbox.destroy()DELETE /sandboxes/:id404 treated as already destroyed
runCommand()POST /sandboxes/:id/exec{command, cwd, env, timeout(sec)}; background wraps in nohup … &
getInfo()(from sandbox record)state → status, timeout_sec → timeout(ms)
getUrl({port})POST /sandboxes/:id/exposeServer resolves the tenant preview domain, never built client-side
filesystem.readFile()GET /sandboxes/:id/fs/read?path=native
filesystem.writeFile()POST /sandboxes/:id/fs/writenative
filesystem.mkdir()POST /sandboxes/:id/fs/mkdirnative, recursive: true
filesystem.readdir()GET /sandboxes/:id/fs?path=native
filesystem.exists()POST /sandboxes/:id/exec (test -e)composed because there is no boolean exists endpoint
filesystem.remove()DELETE /sandboxes/:id/fs?path=native
snapshot.create()POST /sandboxes/:id/snapshotsnative Firecracker checkpoints; name → comment; waits until the snapshot is ready to restore
snapshot.list({instanceId})GET /sandboxes/:id/snapshotsMIOSA snapshots are sandbox-scoped
instance.pause() / .resume()POST /sandboxes/:id/pause / resumesame-box suspend: memory, processes and files survive; Firecracker runtime only (also on getInstance())

Set runtime: "firecracker" per create (sandbox.create({ runtime: "firecracker" })), on the provider, or with MIOSA_RUNTIME=firecracker to create sandboxes on MIOSA's Firecracker runtime (runtime_profile: "standard"), which has pause/resume and snapshots and keeps background processes alive between commands. Unset, MIOSA picks the runtime (currently SOMA, which has none of these). provider.sandbox.pause and provider.snapshot.capabilities declare this as createOptions: { runtime: "firecracker" }. A snapshot captures memory and the whole rootfs (/tmp, /root, /var included), so background processes keep running in the sandbox restored from it; the source keeps running. Snapshots take a couple of minutes to become ready, and snapshot.create() waits for that.

Beyond the ComputeSDK surface, the same API key unlocks the full MIOSA API: sandbox fork/branching, pause/resume, desktop graduation, deploys, and off-host exports.

Testing

pnpm test        # unit tests (mocked fetch, no network)
pnpm typecheck   # tsc --noEmit

License

MIT

版本与发布记录

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

版本发布日期距今
1.2.7latest2026/11/064 天前
1.2.62026/11/046 天前
1.2.52026/10/3011 天前
1.2.42026/10/2812 天前
1.2.32026/10/2813 天前
1.2.22026/10/2813 天前

关于 @computesdk/miosa 的常见问题

@computesdk/miosa 是什么?

MIOSA provider for ComputeSDK - hardware-isolated Firecracker microVM sandboxes with snapshots, persistent graduation, and white-label infrastructure

如何安装 @computesdk/miosa?

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

@computesdk/miosa 支持 TypeScript 吗?

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

@computesdk/miosa 支持 ESM 还是 CommonJS?

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

@computesdk/miosa 可以商用吗?

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

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

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

@computesdk/miosa 还在维护吗?

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