AS AgentScopeAPI 手册 / API Reference

UnixCommandValidator

public class UnixCommandValidator implements CommandValidator
源码Source io/agentscope/core/tool/coding/UnixCommandValidator.java:45–215

Unix 命令校验器,让智能体以受控方式调用外部能力。位于 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.

参数Parameters
名称Name类型Type说明Description
commandString命令(类型 `String`)。The command.
allowedCommandsSet<String>已允许 Commands(类型 `Set`)。The allowed commands.
返回Returns ValidationResult
返回ValidationResult。Returns validation result.
源码Source io/agentscope/core/tool/coding/UnixCommandValidator.java:49–91

extractExecutable

public String extractExecutable(String command)

设置该参数。

Performs the extract executable operation.

参数Parameters
名称Name类型Type说明Description
commandString命令(类型 `String`)。The command.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/tool/coding/UnixCommandValidator.java:93–137

containsMultipleCommands

public boolean containsMultipleCommands(String command)

设置该参数。

Check if the command contains multiple command separators outside of quotes.

参数Parameters
名称Name类型Type说明Description
commandString命令到检查。The command to check
返回Returns boolean
返回布尔值,表示判断结果。true if multiple commands are detected, false otherwise
源码Source io/agentscope/core/tool/coding/UnixCommandValidator.java:169–214

继承成员Inherited Members

继承自Methods inherited from CommandValidator
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.