When us
ing OpenClaw, having the AI assistant execute system commands (such as running scripts or calling APIs) is a common need. But due to its security design, this requires the correct configuration. This article explains in detail how to safely configure OpenClaw to execute system commands.
Problem Background
With OpenClaw’s default configuration, when you try to have the Agent execute a command, you may run into:
- Command ignored: The log shows
ignoring unprofiled safeBins entries - Tool not called: The Agent only uses
memory_searchand doesn’t callexec - Execution timeout: The command is called but returns no result
This is because OpenClaw uses a multi-layered security model to control command execution.
Security Model Overview
OpenClaw’s exec tool has three layers of security control:
|
Complete Configuration Steps
1. Edit the Configuration File
Open ~/.openclaw/openclaw.json and add the tools configuration:
|
2. Configuration Items in Detail
tools.profile
Choose the baseline tool policy:
| Value | Description |
|---|---|
minimal |
Basic tools like read/write/edit only |
messaging |
A tool set suited to message processing |
coding |
Development-related tools (including exec) |
full |
All tools (including browser/cron, etc.) |
tools.exec.ask
The confirmation level before execution:
| Value | Behavior |
|---|---|
off |
Execute directly, no asking |
on-miss |
Ask when not in safeBins |
always |
Always ask for confirmation |
tools.exec.safeBins
The list of allowed binaries. For interpreters (python3, bash, node, etc.), you must also configure safeBinProfiles.
tools.exec.safeBinProfiles
Detailed restrictions for each binary:
| Field | Description | Example |
|---|---|---|
minPositional |
Minimum number of positional args | 1 (at least 1 arg) |
maxPositional |
Maximum number of positional args | 20 (at most 20 args) |
allowedValueFlags |
Allowed value-taking flags | ["--list", "--search"] |
deniedFlags |
Denied flags | ["-rf", "--force"] |
3. Restart the Gateway
|
4. Verify the Configuration
Test command execution:
|
Check the logs to confirm:
|
You should see:
|
Configuration Examples for Common Scenarios
Scenario One: Allow a Specific Python Script
|
Security points:
- Limit the number of args to prevent injection
- Ban pipe and redirection symbols
- Only allow known flags
Scenario Two: Development Environment (Looser)
|
Scenario Three: Production Environment (Strict)
|
Troubleshooting
Problem 1: Command Ignored
Symptom: The log shows ignoring unprofiled safeBins entries
Cause: The files listed in safeBins aren’t real binaries, or safeBinProfiles isn’t configured
Fix:
- For interpreters (python3, bash), you must configure
safeBinProfiles - For script files, run them via an interpreter instead of listing the script directly
Problem 2: Tool Not Called
Symptom: The Agent only uses memory_search and doesn’t call exec
Cause: tools.profile is set incorrectly, or the exec tool isn’t enabled
Fix:
|
Problem 3: Execution Timeout
Symptom: exec is called but doesn’t return
Cause: The default timeout (30 seconds) is too short, or the command itself takes a long time
Fix:
|
Problem 4: Arguments Rejected
Symptom: The command is rejected and the log shows an argument check failed
Cause: allowedValueFlags in safeBinProfiles doesn’t include the flags being used
Fix: Update the allowedValueFlags list, adding the flags you need
Advanced Tips
1. Configure Different Permissions per Agent
|
2. Inject Secrets via Environment Variables
|
3. Configure Trusted Directories
|
Security Best Practices
- Least privilege: Only expose the necessary commands and arguments
- Use absolute paths: Avoid PATH hijacking
- Ban dangerous operations: Reject
-rf,>,|,;, etc. - Enable asking: Use
ask: "always"in production - Audit regularly: Check command execution in the logs
Reference Materials
Configuration version: OpenClaw 2026.3.8
评论
0 条评论