@ computesdk/ 免费样式
自由风格 computeSDK的提供商——为长期运行,复杂的代理任务而设计的全Linux虚拟机,具有即时启动,持续,廉价快照等功能.
安装
npm install @computesdk/freestyle
# .env
FREESTYLE_API_KEY=your_freestyle_api_key
自由式基础图像没有语言运行时间,所以 第一个 账户上的沙盒会烤出一个节点+Python快照一次(~20 s),并用~200–300ms从中取出后的每一个沙盒. 设定 FREESTYLE_SNAPSHOT_ID (或 snapshotId 选项),以跳过烘焙.
使用量
import { freestyle } from '@computesdk/freestyle';
const compute = freestyle({ apiKey: process.env.FREESTYLE_API_KEY });
const sandbox = await compute.instances.create();
const result = await sandbox.runCommand('node -v');
console.log(result.stdout); // "v22.19.0\n"
// Full native filesystem — Freestyle VMs are real Linux guests
await sandbox.filesystem.writeFile('/tmp/app.js', 'console.log("hi")');
console.log(await sandbox.filesystem.readFile('/tmp/app.js'));
await sandbox.destroy();
配置
interface FreestyleConfig {
/** Freestyle API key. Falls back to FREESTYLE_API_KEY. */
apiKey?: string;
/** Snapshot every sandbox boots from. Falls back to FREESTYLE_SNAPSHOT_ID; auto-baked when unset. */
snapshotId?: string;
/** API base URL. Falls back to FREESTYLE_API_URL, then the SDK default. */
baseUrl?: string;
/** Idle seconds before Freestyle stops the VM (default 300). */
idleTimeoutSeconds?: number;
/** Default wall-clock limit for a single command, ms (default 300000; up to 24h per call). */
timeout?: number;
/** Keep the VM after it stops instead of deleting it (default: kept 5 min after stop/pause, so it can be resumed). */
persistent?: boolean;
/** Outbound firewall. Defaults to allow-all outbound; pass { rules: [] } to seal. */
firewall?: { rules: unknown[] };
}
能力
| 特性 | 支助 |
|---|---|
runCommand | ✅ |
| 文件系统: 读取、 写入、 读取、 mkdir、 存在、 删除 | (本国) |
| 抓图: 创建、 列表、 删除 | ✅ |
由 id 重新连接( N)compute.instances.getById(中文(简体) ) | ✅ |
| 列出沙盒 | QQ( 此提供者创建的 VMs) |
长期运行的命令( R)timeout 最高24小时) | ✅ |
标准尺寸(sizeClass: 'lg' | 'xl'和 cpu 编号 : memory (微调) | QQ( 仅来自 4 vCPU / 8 GiB 运行时快照) |
暂停/ 恢复( N)getInstance().pause() 编号 : .start()(中文(简体) ) | ✅(默认沙盒; ephemeral: true VM 无法暂停) |
getUrl (每个端口 URL) | qq — 绘制一个域名 freestyle.domains |
许可证
麻省理工学院