UnixCommandValidator
public class UnixCommandValidator implements CommandValidator
io/agentscope/core/tool/coding/UnixCommandValidator.java:45–215Unix 命令校验器,让智能体以受控方式调用外部能力。位于 io.agentscope.core.tool.coding 包,实现 CommandValidator。核心成员包括 validate、extractExecutable、containsMultipleCommands。
Command validator for Unix-like systems (Linux, macOS).
Validation Order:
-
Extract executable from command (remove quotes, extract first token, remove extensions)
-
If no whitelist configured → allow (backward compatible)
-
Check for multiple command separators → reject if found
-
Check relative path safety (commands starting with
./) → reject if escapes current directory -
Check whitelist → reject if not in whitelist
Multiple Command Detection: Detects Unix-specific separators:
&, &&, |, ||, ;, newline
(ignores separators within quotes or after escape \)
Executable Extraction:
-
Handles quoted commands (single or double quotes)
-
Extracts first token before space/tab
-
Removes script extensions:
.sh,.py,.rb,.pl,.bash,.zsh
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public ValidationResult validate(String command, Set<String> allowedCommands) | 执行校验相关操作。 Performs the validate operation. |
public String extractExecutable(String command) | 设置该参数。 Performs the extract executable operation. |
public boolean containsMultipleCommands(String command) | 设置该参数。 Check if the command contains multiple command separators outside of quotes. |
方法详情Method Detail
validate
public ValidationResult validate(String command, Set<String> allowedCommands)
执行校验相关操作。
Performs the validate operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
command | String | 命令(类型 `String`)。The command. |
allowedCommands | Set<String> | 已允许 Commands(类型 `Set`)。The allowed commands. |
ValidationResultio/agentscope/core/tool/coding/UnixCommandValidator.java:49–91extractExecutable
public String extractExecutable(String command)
设置该参数。
Performs the extract executable operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
command | String | 命令(类型 `String`)。The command. |
Stringio/agentscope/core/tool/coding/UnixCommandValidator.java:93–137containsMultipleCommands
public boolean containsMultipleCommands(String command)
设置该参数。
Check if the command contains multiple command separators outside of quotes.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
command | String | 命令到检查。The command to check |
booleanio/agentscope/core/tool/coding/UnixCommandValidator.java:169–214