跳转到内容

Bash

bash 工具在工作目录中执行 shell 命令。它使用自动分类器来判定命令是只读,还是需要写入/执行权限。

参数类型必填说明
commandstring要执行的 shell 命令
timeoutinteger超时时间(秒,默认 120)

Rusty 会对 bash 命令进行分类,以自动判定权限要求。

这些命令被自动允许并绕过写入权限:

文件检查: lscatheadtailwcfindfilestatdu

Git 读操作: git statusgit loggit diffgit showgit branchgit remote

构建与测试: cargo checkcargo testcargo clippycargo buildnpm testyarn testpytest

包信息: npm listcargo treepip list

系统信息: unamewhoamipwdwhichenvdate

这些命令在 default 模式下需要显式权限:

Git 写操作: git commitgit pushgit checkoutgit mergegit rebasegit stash

文件操作: rmmvcpchmodchownmkdirtouch

包管理: npm installpip installcargo install

执行: dockersshcurlwgetpythonnode

当命令通过管道连接时,分类器会检查整条管道。若所有组成部分都是只读的,则该命令被分类为只读:

Terminal window
# 只读:ls 管道给 grep
ls -la | grep ".rs"
# 写入:重定向到文件
echo "hello" > output.txt

bash 工具在执行命令前通过 check_bash_paths() 进行路径校验:

  • 路径 token 提取:解析命令中的类路径 token(绝对路径、./../~ 展开)。
  • 重定向目标校验:提取并对照工作目录校验重定向目标(>>>2>)。
  • 边界强制:拒绝任何路径 token 或重定向目标解析到工作目录之外的命令。
Terminal window
# 允许:项目内的相对路径
cat src/main.rs
# 阻止:沙箱外的绝对路径
cat /etc/passwd
# 阻止:沙箱外的重定向目标
echo "data" > /tmp/output.txt
{
"command": "cargo check --workspace"
}
{
"command": "git diff --stat HEAD~5",
"timeout": 30
}
{
"command": "python -m pytest tests/ -v",
"timeout": 300
}
  • 以非零状态退出的命令会返回 stderr 输出以及退出码。
  • 超过超时的命令会被终止并返回超时错误。
  • 工作目录始终是项目根目录(或用 --cwd 指定的目录)。