Safety Settings (Shell Execution)
Since Kesoku is an autonomous agent capable of executing terminal commands (such as file modifications, environment checks, and script runs), securing command execution is critical. Kesoku provides robust regex-based filtering of terminal commands before execution.
đ Configuration ([shell])
Command filtering is configured under the [shell] section in config.toml:
[shell]
enabled = true
use_shell = true
mode = "blocklist"
allowlist_patterns = ["^(echo|ls|pwd|cat|git|uv|grep|find|python|sed|awk)(\\s|$)"]
blocklist_patterns = ["(\\b|^)(rm|sudo|shutdown|reboot|mkfs|dd|chmod|chown)(\\b|\\s|$)"]
background_threshold_seconds = 300.0
[shell.forbidden_patterns]
"ping" = "Ping is not allowed for security reasons."
"curl.*evil\\.com" = "Access to evil.com is blocked."
Key Parameters:
-
enabled(boolean, default:true): Enables or disables the command execution tool entirely. If set tofalse, the agent will not be able to execute any command line inputs. -
use_shell(boolean, default:true): Iftrue, command execution usessubprocess.Popen(..., shell=True). This allows operators like pipes (|), redirection (>), and environment expansions. -
mode(string, default:"blocklist"):"blocklist": Commands are allowed by default, unless they match one of the regex patterns inblocklist_patterns."allowlist": Commands are blocked by default, unless they match one of the regex patterns inallowlist_patterns.
-
allowlist_patterns/blocklist_patterns(list of strings): List of regular expressions used to inspect the full command string. -
background_threshold_seconds(float, default:300.0): The maximum execution duration allowed for a command in the foreground. If a command runs longer than this threshold, it is automatically safely detached into a background execution job. -
forbidden_patterns(table/dictionary of regex to string): Custom mapping of regex patterns to custom error messages. Commands matching these patterns are blocked, and their mapped error message is returned to the agent.
âī¸ How Command Inspection Works
When the agent attempts to run a terminal command:
- The command string is stripped of leading/trailing whitespaces.
- The command is evaluated against the keys of
forbidden_patterns. If a match is found, execution is rejected immediately, and the corresponding custom error message is returned. - In Blocklist Mode:
- The command is evaluated against each pattern in
blocklist_patterns. - If any regex matches (e.g. command contains
sudoorrm -rf), execution is rejected immediately, and a warning is returned to the agent.
- The command is evaluated against each pattern in
- In Allowlist Mode:
- The command is evaluated against each pattern in
allowlist_patterns. - If none of the regexes match, execution is rejected immediately.
- The command is evaluated against each pattern in
- If approved, the command runs within a subprocess container, and its
stdoutandstderrstreams are captured.