Skip to content

feat(security): add command safety guardrails, timeouts, and output truncation - #33

Open
chetna123-ch wants to merge 5 commits into
Harshbansal8705:mainfrom
chetna123-ch:feat/secure-run-command
Open

chetna123-ch wants to merge 5 commits into
Harshbansal8705:mainfrom
chetna123-ch:feat/secure-run-command

Conversation

@chetna123-ch

@chetna123-ch chetna123-ch commented Oct 7, 2026 •

Copy link
Copy Markdown

📌 Description

This PR addresses safety and resource management issues when executing voice shell commands via run_command. It introduces a risk check against dangerous command patterns, requires explicit confirmation for flagged execution, enforces process timeouts, and truncates oversized output to protect LLM context limits.

🛠️ Changes Implemented

  • Config Updates (src/config.py, .env.example): Added COMMAND_SAFETY_CHECK, COMMAND_TIMEOUT, COMMAND_MAX_OUTPUT_CHARS, and DANGEROUS_PATTERNS.
  • Pattern Matcher (src/utils/safety.py): Implemented regex-based risk engine to detect destructive commands (rm -rf, sudo, mkfs, dd, shutdown, etc.).
  • Execution Safeguards (run_command):
    • Enforced confirmation dialog in overlay before running flagged commands.
    • Added process execution timeout (subprocess.TimeoutExpired handling).
    • Truncated stdout/stderr output exceeding character limits with a visible notification.
  • Testing & Docs: Added test cases in tests/test_safety.py and documented new configuration flags in README.md.

🧪 Testing Verification

  • Safe commands (ls, git status) execute without confirmation.
  • Flagged commands trigger confirmation UI before running.
  • Long-running processes time out gracefully and return error strings.
  • Large command outputs are truncated properly.
  • All unit tests passing via pytest tests/ -v.

Contribution under OSCI '26.

issue number #28

@Harshbansal8705

Copy link
Copy Markdown
Owner

@chetna123-ch link the issue this PR is for in the description

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants