safe-agent-executor
v1.0.0
Published
Zero-dependency sandbox wrapper to run CLI agent commands safely, blocking destructive patterns and enforcing execution limits.
Maintainers
Readme
safe-agent-executor
CLI Agent Sandbox Guard: A zero-dependency safety wrapper to execute terminal commands under validation, checking for malicious/destructive code patterns and setting strict execution limits.
⚡ Features
- Zero Runtime Dependencies: Fast and secure native command execution.
- Dangerous Commands Shield: Statically parses and blocks destructive commands like recursive deletes (
rm -rf *), write attempts to system sectors, and git force-pushes. - Execution Limits: Enforces customizable execution timeouts (in milliseconds) and terminates hanging processes cleanly.
- Node spawn Wrapper: Forwards child output stream buffers and exit code signals accurately.
📦 Installation
npm install safe-agent-executor🚀 Usage
1. CLI Wrapper
Run a command through the safe sandbox:
npx safe-agent-executor "echo 'hello'"
# Blocking destructive commands
npx safe-agent-executor "rm -rf *"
# Output: [Security Violation] Dangerous command blocked by safety policy.
# Force allow dangerous operations
npx safe-agent-executor "git push origin main --force" --allow-dangerous
# Enforcing a 500ms timeout
npx safe-agent-executor "sleep 2" --timeout 5002. Programmatic API
import { runCommand } from 'safe-agent-executor';
try {
const result = await runCommand("npm run dev", [], {
timeout: 5000 // limit to 5 seconds
});
if (result.timedOut) {
console.log("Process timed out and was terminated.");
} else {
console.log("Output:", result.stdout);
}
} catch (err) {
console.error("Execution blocked:", err.message);
}📄 License
MIT License.
