全部產品
Search
文件中心

Function Compute:運行命令

更新時間:Jul 22, 2026

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。

後續閱讀