@computesdk/neevcloud

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

NeevCloud 计算SDK 的提供者 - 安全云沙盒,有命令执行、文件系统访问和预览 URL

中文使用文档
文档目录14 节
  1. 安装
  2. 设置
  3. 快速启动
  4. 配置
  5. 特征
  6. API 参考
  7. 命令执行
  8. 文件系统操作
  9. 预览 URL
  10. 沙盒管理
  11. 抓图
  12. 模板
  13. 在计算SDK表面之外
  14. 许可证

@computesdk/neevcloud (英语)

尼夫克卢德 提供方 计算SDK ——在安全的云沙箱中运行命令并管理文件.

安装

npm install @computesdk/neevcloud

设置

从 NeevCloud 控制台获取一个 API 密钥, 并记录 Org 和投影 沙盒应该居住, 然后设定 :

export NEEV_API_KEY=sk-nc-...
export NEEV_ORG_ID=org-...
export NEEV_PROJECT_ID=prj-...

快速启动

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

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

const res = await sandbox.runCommand('echo "Hello from NeevCloud!"');
console.log(res.stdout); // "Hello from NeevCloud!"

await sandbox.filesystem.writeFile('app.txt', 'hi');
console.log(await sandbox.filesystem.readFile('app.txt')); // "hi"

const url = await sandbox.getUrl({ port: 3000 });
console.log(url); // https://3000-<id>.<region>.neevsandbox.app

await sandbox.destroy();

配置

neevcloud(config) 接受 { apiKey?, orgId?, projectId?, timeout? }。每个字段都是可选的,省略时从匹配的环境变量中读取,所以大多数呼叫者都可以使用 neevcloud() 没有争论.

interface NeevCloudConfig {
  /** NeevCloud API key. Read from NEEV_API_KEY when omitted. */
  apiKey?: string;
  /** Org the sandboxes belong to. Read from NEEV_ORG_ID when omitted. */
  orgId?: string;
  /** Project the sandboxes belong to. Read from NEEV_PROJECT_ID when omitted. */
  projectId?: string;
  /** Request timeout in milliseconds. */
  timeout?: number;
}

特征

  • 命令执行 ——运行 shell 命令,缓冲或流出,前景或背景.
  • 文件系统访问 ——读取,写出,列出,stat,并删除文件.
  • 预览 URL ——在公共HTTPS URL上曝光任何端口 getUrl({ port })。 。 。 .
  • 弹性靴子 ——从目录模板开始,原始OCI图像,快照,或平台默认,有名称,env vars,大小,和寿命.
  • 抓图 ——保存运行中的沙盒的内存和文件系统,再从中提供出新的沙盒.
  • 模板 ——列出沙盒模板目录.

API 参考

命令执行

// Buffered — resolves with the full result
const res = await sandbox.runCommand('ls -la');
console.log(res.stdout, res.exitCode, res.durationMs);

// Streamed — pass output callbacks to receive chunks as they arrive
await sandbox.runCommand('npm install', {
  onStdout: (chunk) => process.stdout.write(chunk),
  onStderr: (chunk) => process.stderr.write(chunk),
});

// Background — returns immediately, leaves the process running
await sandbox.runCommand('python3 -m http.server 3000', { background: true });

命令会从工作空间根穿过一个 shell(/workspace),所以管道和重定向工作. 一个亲戚 cwd 从工作空间根解析;使用绝对根。 流出输出来自NeevCloud exec API,所以沙盒内的任何端口都不得被接通. 一个超过它的命令 timeout 返回退出代码 124 和它迄今为止的产出.

文件系统操作

await sandbox.filesystem.writeFile('data/input.csv', csv);
const content = await sandbox.filesystem.readFile('data/input.csv');
await sandbox.filesystem.mkdir('data/output');
const entries = await sandbox.filesystem.readdir('data');
const present = await sandbox.filesystem.exists('data/input.csv');
await sandbox.filesystem.remove('data/input.csv');

路径意味着相同的东西 filesystem 电话和在 runCommand: 从工作空间根解决相对路径(/workspace),并使用绝对路径。 工作空间内部的路径通过 NeevCloud 文件 API; 其外的绝对路径, 如 /tmp/x穿过外壳.

预览 URL

// Start a server, then expose its port over public HTTPS
await sandbox.runCommand('python3 -m http.server 3000', { background: true });
const url = await sandbox.getUrl({ port: 3000 });

沙盒管理

const sandbox = await compute.instances.create({ templateId: 'sb-ubuntu-24-04-minimal' });
const sandbox = await compute.instances.create({ image: 'docker.io/library/python:3.12' });

// Name, env vars, size (cpu cores, memory in MB) and lifetime (ms; deleted when it elapses)
const sandbox = await compute.instances.create({
  name: 'build-42',
  envs: { NODE_ENV: 'production' },
  cpu: 2,
  memory: 4096,
  timeout: 30 * 60 * 1000,
});

const info = await sandbox.getInfo(); // { id, provider, status, createdAt, timeout, metadata }
const all = await compute.instances.list();
const one = await compute.instances.getById(id); // null if not found
await sandbox.destroy();

templateId 财务报告和审定财务报表 image 相互排斥; 省略两个平台默认值。 通过一个 AbortSignal 作为 signal 取消创建并删除已请求的沙盒.

抓图

// Save memory and filesystem; resolves once the snapshot is ready to restore
const snapshot = await compute.snapshot.create(sandbox.instanceId, { name: 'after-install' });

// Boot a new sandbox from it
const copy = await compute.instances.create({ snapshotId: snapshot.id });

const forOne = await compute.snapshot.list({ instanceId: sandbox.instanceId });
const all = await compute.snapshot.list(); // visits every sandbox in the project
await compute.snapshot.delete(snapshot.id);

模板

const templates = await compute.template.list();

模板目录由NeevCloud管理,所以 template.create 财务报告和审定财务报表 template.delete 掷出. 从您自己的图像启动 create({ image }),或用 snapshot.create。 。 。 .

在计算SDK表面之外

对于计算SDK合同之外的能力——暂停/恢复、交互式PTYs、流程监督、Egreat-limits、分叉和回滚以及审计日志——达到基本 @neevcloud/sdk 控件 :

const native = sandbox.getInstance();
await native.pause();
await native.resume();
const copy = await native.fork('copy-of-build');

许可证

麻省理工学院

版本与发布记录

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

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

关于 @computesdk/neevcloud 的常见问题

@computesdk/neevcloud 是什么?

NeevCloud 计算SDK 的提供者 - 安全云沙盒,有命令执行、文件系统访问和预览 URL

如何安装 @computesdk/neevcloud?

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

@computesdk/neevcloud 支持 TypeScript 吗?

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

@computesdk/neevcloud 支持 ESM 还是 CommonJS?

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

@computesdk/neevcloud 可以商用吗?

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

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

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

@computesdk/neevcloud 还在维护吗?

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