Skip to content

Conversation

gonzalo123
Copy link
Contributor

New feature for python_repl tool

  • Add SecurityMode enum with NORMAL and RESTRICTED modes
  • Implement ASTSecurityValidator for static code analysis
  • Add file path whitelist system with PYTHON_REPL_ALLOWED_PATHS
  • Block dangerous imports, builtins, and attributes in restricted mode
  • Add resource limits (memory, CPU) with configurable timeouts
  • Implement protection against path traversal and symlink bypass
  • Add comprehensive test suite covering all security features
  • Update documentation with security configuration examples

BREAKING CHANGE: None - feature is opt-in via PYTHON_REPL_RESTRICTED_MODE=true

Environment Variables:

  • PYTHON_REPL_RESTRICTED_MODE: Enable/disable restricted mode (default: false)
  • PYTHON_REPL_ALLOWED_PATHS: Comma-separated allowed directories
  • PYTHON_REPL_ALLOW_CURRENT_DIR: Allow current directory access (default: true)
  • PYTHON_REPL_TIMEOUT: Execution timeout in seconds (default: 30)
  • PYTHON_REPL_MEMORY_LIMIT_MB: Memory limit in MB (default: 100)

Refs: #192

Description

This feature adds configurable restricted modes to the Python REPL tool, providing AST-based code validation and execution restrictions to prevent potentially dangerous operations while maintaining full backward compatibility.

Related Issues

#192

Documentation PR

Type of Change

New feature for existing tool

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@gonzalo123 gonzalo123 requested a review from a team as a code owner August 3, 2025 14:18
…trictions

- Add SecurityMode enum with NORMAL and RESTRICTED modes
- Implement ASTSecurityValidator for static code analysis
- Add file path whitelist system with PYTHON_REPL_ALLOWED_PATHS
- Block dangerous imports, builtins, and attributes in restricted mode
- Add resource limits (memory, CPU) with configurable timeouts
- Implement protection against path traversal and symlink bypass
- Add comprehensive test suite covering all security features
- Update documentation with security configuration examples

BREAKING CHANGE: None - feature is opt-in via PYTHON_REPL_RESTRICTED_MODE=true

Environment Variables:
- PYTHON_REPL_RESTRICTED_MODE: Enable/disable restricted mode (default: false)
- PYTHON_REPL_ALLOWED_PATHS: Comma-separated allowed directories
- PYTHON_REPL_ALLOW_CURRENT_DIR: Allow current directory access (default: true)
- PYTHON_REPL_TIMEOUT: Execution timeout in seconds (default: 30)
- PYTHON_REPL_MEMORY_LIMIT_MB: Memory limit in MB (default: 100)

Refs: strands-agents#192
@gonzalo123 gonzalo123 force-pushed the feature/python-repl-security-modes branch from 332d2b9 to 3a33604 Compare August 30, 2025 10:35
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.

1 participant