Skip to main content

Security Remediation Agent for Python codebases

Project description

Refactoring Agent – Security Remediation for Legacy Python

Refactoring Agent is a command-line tool that scans your Python codebase for legacy patterns and security risks, and optionally asks an LLM to propose safe, modern fixes.

It is built for teams who are migrating large, messy, “battle-tested” codebases and want:

  • Static checks for legacy constructs (e.g. raw_input, old print statements)
  • Security scanning for dangerous APIs (eval, exec, os.system, pickle)
  • Optional AI-based refactoring suggestions (OpenAI, Ollama, or a mock provider)
  • CI-friendly CLI and GitHub Actions integration

Features

🛡️ Security Scanning (Enterprise Grade)

Refactoring Agent goes beyond simple linting. It proactively hunts for Critical Vulnerabilities (OWASP Top 10 vectors):

ID Severity Description
security_eval Critical Detects arbitrary code execution via eval().
security_exec Critical Detects dynamic code execution via exec().
security_os_system Critical Flags os.system() which is vulnerable to shell injection.
security_subprocess_shell Critical Detects subprocess.Popen(..., shell=True) – a common RCE vector.
security_pickle_untrusted Critical Blocks pickle.load() on untrusted data (Insecure Deserialization).
security_insecure_random Major Warns about using random for secrets/tokens (suggests secrets module).

🤖 AI-assisted Refactoring & Auto-Fix

The tool can automatically fix issues using LLMs. It supports two modes:

1. Interactive Mode (Default)

Best for local development. The tool shows you a diff for every file and asks for confirmation. ```bash refactor-agent check . --ai-fix ``` Output: Shows diff, then asks Apply this fix to src/main.py? [y/n].

2. Non-Interactive / CI Mode (--yes)

Best for CI/CD pipelines or when you trust the AI. ```bash refactor-agent check . --ai-fix --yes ``` Behavior: Applies all fixes automatically without prompts.

Note: If you run --ai-fix in a CI environment (no TTY) without --yes, the tool will fail with an error to prevent hanging.


Installation

Install from PyPI: ```bash pip install refactoring-agent ```

Quickstart

Initialize configuration: ```bash refactor-agent init ```

Scan the current directory: ```bash refactor-agent check . ```

Generate an HTML report: ```bash refactor-agent check . --html-report report.html ```

Using AI Suggestions

OpenAI provider

```bash export RA_LLM_PROVIDER="openai" export OPENAI_API_KEY="your-openai-key"

refactor-agent check demo_legacy --ai-fix --dry-run ```

Ollama provider (Local LLM)

```bash export RA_LLM_PROVIDER="ollama" export RA_LLM_MODEL="llama3"

refactor-agent check demo_legacy --ai-fix --dry-run ```

Configuration

Refactoring Agent allows fine-grained control over rules via pyproject.toml.

```toml [tool.refactoring-agent.rules]

Strict security

security_eval = "error" security_subprocess_shell = { mode = "error", severity = "critical" }

Relaxed legacy checks (warnings only)

legacy_print = "warn" ```

GitHub Action example

```yaml name: Security Scan on: [push, pull_request] jobs: refactor-agent: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: { python-version: "3.11" } - run: pip install refactoring-agent - name: Run Scan & Auto-Fix (Dry Run) run: | refactor-agent check .
--ai-fix --dry-run
--provider openai --api-key ${{ secrets.OPENAI_KEY }}
--html-report report.html ```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

refactoring_agent-3.12.3.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

refactoring_agent-3.12.3-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file refactoring_agent-3.12.3.tar.gz.

File metadata

  • Download URL: refactoring_agent-3.12.3.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for refactoring_agent-3.12.3.tar.gz
Algorithm Hash digest
SHA256 4f264866ae30a44d45d76dec1cf16ad3a38d659fcea5f294bb553294646ad38b
MD5 15d6c71e461a02a8a654668f9a2d9304
BLAKE2b-256 9cf25ca53bc671a07402c1117abfaa0ae73b465e7a0b3962068807782bd3b8ad

See more details on using hashes here.

File details

Details for the file refactoring_agent-3.12.3-py3-none-any.whl.

File metadata

File hashes

Hashes for refactoring_agent-3.12.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ac405da6ed8163f3c1cba6dbb2b0f9918c7cb49edcafbaaccfc6b9b222a27695
MD5 ac69ab8a78016057bdf5da2efa0d2415
BLAKE2b-256 c734168bd453a632a67fea6daddcc23dacf15c6661ad4d787642747b1231ec86

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page