@ computesdk/ arker (帮助)
计算SDK的 Arker 提供者——运行代码 阿克尔 沙盒 VMs 有持久的每VM文件系统.
安装
npm install @computesdk/arker
设置
- 获取您的 Arker API 密钥( 启动于
ark_从 方舟鱼.ai。 。 。 . - 设置环境变量 :
export ARKER_API_KEY=ark_live_your_api_key_here
默认情况下,提供者的目标是 aws-us-east-1 区域。 选择另一个区域 region 编号 : ARKER_REGION。 。 。 .
快速启动
配置 compute 与 Arker 提供者创建沙盒 :
import { compute } from 'computesdk';
import { arker } from '@computesdk/arker';
compute.setConfig({
provider: arker({ apiKey: process.env.ARKER_API_KEY }),
});
const sandbox = await compute.instances.create();
const result = await sandbox.runCommand('node -v');
console.log(result.stdout); // v18.x
await sandbox.destroy();
或者在只需要一个供货商时直接给供货厂打电话:
import { arker } from '@computesdk/arker';
const sdk = arker({ apiKey: process.env.ARKER_API_KEY });
const sandbox = await sdk.sandbox.create();
沙盒是如何创建的
Arker 禁用直接 VM 创建—— 每个沙盒是 从源 VM 防御。 。 。 . create() 叉车 ubuntu-small 金色(Node.js + Python 预设)默认. 来源可以选择两种方式:
- 名称 - 一个金色/模版,通过
source在配置中或templateId在创建选项中. - 依编号 - 通过下列途径,确定一个具体的现有VM:
snapshotId在创建选项中。 这个instanceId返回时间create()本身是一个有效的源,所以这个分支从它的当前状态(Arker相当于快照还原)中分出一个沙盒. 如果两者都给出了,snapshotId赢了.
// Default: forks the `ubuntu-small` golden
const sandbox = await sdk.sandbox.create();
// Pick a golden globally for this provider
const heavy = arker({ apiKey, source: 'ubuntu-full' });
// ...or per sandbox, by name
const other = await sdk.sandbox.create({ templateId: 'ubuntu-full' });
// Fork an existing sandbox by id — branches from its current state
const forked = await sdk.sandbox.create({ snapshotId: sandbox.instanceId });
配置
环境变量
export ARKER_API_KEY=ark_live_your_api_key_here
export ARKER_REGION=aws-us-east-1 # optional, this is the default
export ARKER_SOURCE=ubuntu-small # optional default golden
配置选项
interface ArkerConfig {
/** Arker API key (starts with `ark_`). Falls back to ARKER_API_KEY. */
apiKey?: string;
/** Region, e.g. `aws-us-east-1`. Falls back to ARKER_REGION, then the us-east-1 default. */
region?: string;
/** Golden source VM to fork on create(). Falls back to ARKER_SOURCE, then `ubuntu-small`. */
source?: string;
}
API 参考
命令执行
// Shell command
const result = await sandbox.runCommand('echo hello');
// Run a script via heredoc
const result = await sandbox.runCommand(`python3 - <<'PY'
print("Hello from Python")
PY`);
// With environment and working directory
const result = await sandbox.runCommand('npm test', {
cwd: '/app',
env: { CI: '1' },
});
runCommand 返回时 { stdout, stderr, exitCode, durationMs }。 。 。 .
文件系统操作
文件系统操作在VM中作为 shell 命令运行,并在任意路径上工作.
await sandbox.filesystem.writeFile('/tmp/hello.txt', 'hi');
const content = await sandbox.filesystem.readFile('/tmp/hello.txt');
await sandbox.filesystem.mkdir('/tmp/data');
const entries = await sandbox.filesystem.readdir('/tmp');
const exists = await sandbox.filesystem.exists('/tmp/hello.txt');
await sandbox.filesystem.remove('/tmp/hello.txt');
沙盒管理
const sandbox = await sdk.sandbox.create();
const info = await sandbox.getInfo(); // { id, provider, status, createdAt, ... }
const all = await sdk.sandbox.list(); // VMs visible to the API key
const existing = await sdk.sandbox.getById(sandbox.instanceId);
await sandbox.destroy();
特征
- ✅ 命令执行 ——全外壳,节点js & Python 预装(
ubuntu-small(中文(简体) ) - ✅ 文件系统操作 连续的每VM文件系统(阅读/写作/列表/mkdir/存在/删除)
- ✅ 快速冷却开始 - 将默认的金靴扔到地上..
- ✅ 自动重试 - 基础
@arker-ai/sdk重试瞬间故障(HTTP 429/502/503/504和瞬间后端错误)
限制
- 创建仅为叉 直接的VM创建被禁用;
create()叉出一个金色的名字(templateId编号 :source)或以id为单位的现有 VM(snapshotId) (中文(简体) ). 没有单独的快照店,但任何instanceId能够重起炉子snapshotId。 。 。 . getUrl不支持 - Arker不披露每个港口的URL;getUrl掷出. 以网络可达性为条件的VMs 获得一个稳定的每VM主机名——见 方舟SDK 分叉网络选项.getInfo状态 - 总是报告running; 闲置的沙盒会在其下一个命令上自动恢复.
支助
许可证
麻省理工学院