@computesdk/run-cloud (英语)
运行云 计算SDK的提供者。 在可配置的CPU、内存和磁盘、本地文件读取、快照和自动闲置暂停的快速鞭炮微VM沙盒内运行命令.
安装
npm install computesdk @computesdk/run-cloud
在其中创建 API 密钥 运行云盘 并导出 :
export RUN_CLOUD_API_KEY=rc_live_your_key
RUN_CLOUD_API_TOKEN 被支持为倒向兼容的别名。 设定 RUN_CLOUD_API_URL 仅在瞄准自定义运行云部署时.
使用量
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',
});
供应商工厂也可以直接使用:
const cloud = runCloud({ apiKey: process.env.RUN_CLOUD_API_KEY });
const sandbox = await cloud.sandbox.create({ cpu: 1, memory: 1024 });
配置
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接受分数的 vCPU 值.memory以MIB计量.disk是 GiB 可写入的磁盘配额 .timeout财务报告和审定财务报表commandTimeout数以毫秒计.tunnelTtlSeconds控制公共端口 URL 寿命并默认为1小时.idlePauseSeconds秒; 设置为0以禁用自动暂停.templateId财务报告和审定财务报表image二者都选择已注册的 Run Cloud OCI 图像 .snapshotId恢复先前创建的“运行云”快照.- 新鲜的创建接受每个创建
cpu, (中文(简体) ),memory, (中文(简体) ),disk, (中文(简体) ),idlePauseSeconds, (中文(简体) ),timeoutSeconds, (中文(简体) ),region, (中文(简体) ),name, (中文(简体) ),orgId,以及idempotencyKey超载. - 快照恢复接受
cpu, (中文(简体) ),memory, (中文(简体) ),disk, (中文(简体) ),timeoutSeconds, (中文(简体) ),region, (中文(简体) ), 财务报告和审定财务报表name超载 无法应用的 API 选项被拒绝 而不是被无声地忽略.
运行 Cloud 目前不支持持久性沙盒级 envs。通过命令范围变量,变量为:
await sandbox.runCommand('echo "$MODEL"', {
env: { MODEL: 'gpt-5' },
});
支助业务
| 方法 | 支助 | 页:1 |
|---|---|---|
create | ✅ | 新鲜的图像启动或快照还原;恢复安全覆盖得到验证和应用. |
getById | ✅ | 回返 null 当沙盒不存在时. |
list | ✅ | 列出运行 API 密钥可见的沙盒 . |
destroy | ✅ | 沙盒已经没了就更能说明问题了. |
runCommand | ✅ | 支助 cwd, 命令- 范围化的 env, 超时, 流回调, 和离散的背景命令 . |
getInfo | ✅ | 刷新运行云的状态和资源元数据 . |
getUrl | ✅ | 打开过期的能力 URL而不使沙盒具有持久性 . |
| 文件系统 | ✅ | 原生读取; shell-backed write, mkdir, 列表, 存在并去除. |
| 抓图 | ✅ | 通过 snapshotId。 。 。 . |
sandbox.getInstance() 返回 a RunCloudSandbox 包含官员的控件 Client 和最新的本土沙盒记录.
隧道主机名是随机无记名能力. 不要把它们写到公共日志上. 它们自动过期,被删除隧道或沙盒后被移除.