islo
最后更新 查看 Markdown 源文件
islo 适配器通过调用本地 islo CLI 将命名的 islo 沙箱适配为 Flue 的沙箱接口。它专为安装了该二进制文件并能启动远程命令的 Node.js 服务器、容器或 CI 运行器设计。
快速开始
使用 islo 蓝图为现有 Flue 项目添加命名远程沙箱能力。在终端或你选择的编码智能体中运行以下命令:
flue add sandbox islo
概述
islo 蓝图在你的源码根目录下创建 sandboxes/islo.ts,不添加 npm 依赖。生成的适配器使用 Node 的子进程 API,需要已认证的 islo 二进制文件以及应用管理的沙箱名称。
// flue-blueprint: sandbox/islo@1
import { spawn } from 'node:child_process';
import { sandboxFromDriver } from '@flue/runtime';
import type { SandboxDriver, SandboxFactory, Sandbox, FileStat } from '@flue/runtime';
export interface IsloAdapterOptions {
cwd?: string;
cliPath?: string;
}
const q = (s: string) => `'${s.replace(/'/g, `'\\''`)}'`;
class IsloSandboxDriver implements SandboxDriver {
constructor(
private name: string,
private cliPath: string,
) {}
async exec(
command: string,
options?: {
cwd?: string;
env?: Record<string, string>;
timeoutMs?: number;
signal?: AbortSignal;
},
): Promise<{ stdout: string; stderr: string; exitCode: number }> {
const cd = options?.cwd ? `cd ${q(options.cwd)} && ` : '';
const envPrefix = options?.env
? Object.entries(options.env)
.map(([k, v]) => `${k}=${q(v)}`)
.join(' ') + ' '
: '';
const tmo =
typeof options?.timeoutMs === 'number' ? `timeout ${options.timeoutMs / 1000} ` : '';
const remote = `${envPrefix}${tmo}bash -lc ${q(cd + command)}`;
const args = ['--output', 'json', 'use', this.name, '--', 'bash', '-lc', remote];
/* ... 启动 islo CLI 并映射其输出和退出码 ... */
}
/* ... 使用带引号的远程 shell 命令生成的文件操作 ... */
}
export function islo(name: string, options?: IsloAdapterOptions): SandboxFactory {
const cliPath = options?.cliPath ?? 'islo';
return {
async createSandbox(): Promise<Sandbox> {
const sandboxCwd = options?.cwd ?? '/workspace';
const driver = new IsloSandboxDriver(name, cliPath);
return sandboxFromDriver(driver, sandboxCwd);
},
};
}将沙箱名称传递给 islo(...),并将返回的工厂分配给智能体的 sandbox 属性。Flue 从 /workspace 解析相对路径;适配器将 timeoutMs 从毫秒转换为沙箱内 GNU timeout 使用的秒数,而 CLI 处理远程执行和文件操作。
配置
| 变量 | 用途 |
|---|---|
ISLO_API_KEY | 替代认证 — 当现有 CLI 认证不可用时,认证服务器或 CI 操作。 |
| 覀求 | 用途 |
|---|---|
| 现有的 CLI 认证或 API 密钥 | 必需 — 通过 CLI 会话或 ISLO_API_KEY 进行认证。 |
| Node.js 子进程能力 | 必需 — 允许适配器调用 CLI。 |
PATH 中的 islo 二进制文件 | 必需 — 执行远程 shell 和文件操作。 |
| 命名的 islo 沙箱 | 必需 — 标识应用或部署管理的沙箱。 |
适用场景
当应用可以依赖主机安装的 CLI 并希望从 Node 执行环境连接到命名沙箱时,使用 islo。不要在 Cloudflare Workers 或其他无法执行原生子进程的运行时中使用它。
适配器通过 CLI 运行远程 shell/文件工作;确保其主机进程、凭据和智能体输入符合你预期的信任边界。