Skip to content

skill_run 开启 allowed_cmds 后,引号里的 > | ; 也会被拒绝 #348

Closed

Description

@kinolo

配置了 allowed_cmds(或 denied_cmds)之后,如果命令里出现 > | ; & <,哪怕是在引号里,skill_run 也会直接报 shell meta character ... is not allowed。

from trpc_agent_sdk.skills.tools._skill_run import _split_command_line

_split_command_line('python3 calc.py --expr "A > 5"')  # ValueError
_split_command_line("grep -E 'a|b' data.txt")         # ValueError
_split_command_line('echo "x;y"')                     # ValueError

原因是 _split_command_line 在解析引号之前,先用 if ch in cmd 把整条命令扫了一遍,引号里的字符也被算进去了。

受限模式下命令本来就不走 shell(local 用的是 create_subprocess_exec,container 和 cube 会对每个参数做 shell quote),所以引号里的这些字符其实是安全的。但是会出现一个实际问题是:如果skill 需要传比较表达式、正则这类参数,模型收到报错后会反复改写命令,一直绕不过去。

建议把检查挪到逐字符解析的循环里,只拦引号外、而且没被转义的字符:

-    for ch in _DISALLOWED_SHELL_META:
-        if ch in cmd:
-            raise ValueError(...)
     ...
     for ch in cmd:
         ...
+        if not in_single and not in_double and ch in _DISALLOWED_SHELL_META:
+            raise ValueError(...)
         if not in_single and not in_double and ch in (" ", "\t"):

Activity

  1. raychen911 commented on Sep 29, 2026

    @raychen911
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions