运行命令

更新时间:
复制 MD 格式

Commands 用于在 Sandbox 中执行命令或进程,是 Agent 工具调用、代码执行和环境检查的基础能力。

运行命令

运行一条命令并读取 stdout:

Python 示例:

result = sandbox.commands.run("ls -lh /")
print(result.stdout.strip())

TypeScript 示例:

const result = await sandbox.commands.run("ls -lh /");
console.log(result.stdout.trim());

已兼容方法

  • sandbox.commands.run():启动进程并等待结果。

  • sandbox.commands.list():列出运行中的进程。

  • sandbox.commands.connect():连接到已有进程。

  • sandbox.commands.sendStdin():发送标准输入。

  • sandbox.commands.kill():终止进程。

交互式终端和依赖 TTY 的任务使用独立的 sandbox.pty API,参见 PTY

后续阅读