Skip to main content

Exec 工具

在工作区运行 shell 命令。通过 process 支持前台和后台执行。

参数

  • command(必需)
  • workdir(默认当前工作目录)
  • env(键/值覆盖)
  • yieldMs(默认 10000):延迟后自动切换到后台
  • background(布尔):立即后台运行
  • timeout(秒,默认 1800):超时杀死进程
  • pty(布尔):有条件时在伪终端中运行
  • host(sandbox | gateway | node):执行位置
  • security(deny | allowlist | full):gateway/node 的执行模式
  • ask(off | on-miss | always):gateway/node 的批准提示
  • node(字符串):host=node 时的节点id/名称
  • elevated(布尔):请求提升模式(gateway 主机)

配置

{
  tools: {
    exec: {
      pathPrepend: ["~/bin", "/opt/oss/bin"],
      notifyOnExit: true,
      approvalRunningNoticeMs: 10000,
      host: "sandbox",
      security: "allowlist",
      ask: "on-miss",
    },
  },
}

示例

前台运行:
{ "tool": "exec", "command": "ls -la" }
后台运行 + 轮询:
{"tool":"exec","command":"npm run build","yieldMs":1000}
{"tool":"process","action":"poll","sessionId":"<id>"}

Exec 批准

沙箱代理可要求每次在 gateway 或节点主机上执行 exec 之前必须获得批准。详见 Exec 批准

apply_patch(实验性)

apply_patch 是 exec 的子工具,用于结构化多文件编辑。需显式开启:
{
  tools: {
    exec: {
      applyPatch: { 
        enabled: true, 
        workspaceOnly: true, 
        allowModels: ["gpt-5.2"] 
      },
    },
  },
}