Building an AI-Agent Based Python Security Scanner.
The Problem
Manual security scanning of Python dependencies is time-consuming and error prone. Developers often skip vulnerability checks during development, leading to security debt that compounds over time. Existing tools either lack intelligence or require complex setup and maintenance.
I needed a solution that could automatically scan Python packages, identify vulnerabilities, and provide actionable recommendations without requiring extensive security expertise. Or at most allow vibe coders to scan all the packages in their code with minimal set up.
The Solution: AI Agent-based scanner
An AI agent-based security scanner that uses intelligent agents to analyze Python dependencies and identify vulnerabilities. It combines multiple data sources with AI reasoning to provide comprehensive security analysis.
Architecture Overview
Technical Implementation
Core Components:
Key Technologies:
Implementation Challenges
Challenge 1: Inconsistent AI Output
The AI agent produced different output structures across runs:
python
# Sometimes:
{'vulnerable_packages': {'pkg': [...]}}
# Other times:
{'executive_summary': {'vulnerable_packages': {'pkg': [...]}}}
For anyone interested in understanding more about AI Agents, I would recommend the agents-course (Hugging Face Agents Course).
Solution: Use Agent Tools
Implemented a robust FinalAnswerTool with structured validation.
python
class FinalAnswerTool(Tool):
def forward(self, answer: Any) -> Dict[str, Any]:
if isinstance(answer, dict):
standardized = {
"vulnerable_packages": {},
"upgrade_recommendations": {},
"overall_risk_assessment": "No assessment provided"
}
# Handle multiple possible structures
if "vulnerable_packages" in answer:
standardized["vulnerable_packages"] = answer["vulnerable_packages"]
elif "executive_summary" in answer and isinstance(answer["executive_summary"], dict):
if "vulnerable_packages" in answer["executive_summary"]:
standardized["vulnerable_packages"] = answer["executive_summary"]["vulnerable_packages"]
return standardized
Challenge 2: Multi-Source Data Integration
Different APIs return vulnerability data in incompatible formats.
Recommended by LinkedIn
Solution: Use a Parser.
Created unified data models and source-specific parsers that normalize data into a consistent structure.
Usage Example
bash
# Install dependencies
pip install motionstream
# Scan requirements file
motionstream scan requirements.txt
# Generate JSON report
motionstream scan requirements.txt --output json
# Generate HTML report
motionstream scan environment.yml --output html
Sample Output
🔒 MotionStream Security Report
📦 Scanned 3 packages:
✓ requests 2.32.4
✓ pandas None
❌ browser-use 0.1.44 - HIGH vulnerabilities found
🔍 Security Issues Found:
⚠ HIGH: browser-use 0.1.44 has file access vulnerabilities
Impact: package
Fix: pip install browser-use>=0.2.6
📊 Summary: 1 vulnerabilities found (0 Critical, 1 High)
🎯 Recommendation: Update vulnerable packages immediately
Results and Impact
Lessons Learned
Future Enhancements
Immediate Next Steps:
Long-term Vision:
Technical Specifications
System Requirements:
Performance Metrics:
Conclusion
This demonstrates how AI agents can effectively automate security scanning while maintaining accuracy and usability. The key success factors were handling AI output inconsistency, robust error handling, and focusing on developer experience.
The project proves that combining multiple data sources with AI reasoning can produce more intelligent security analysis than traditional rule-based approaches. Source code and documentation available on GitHub: https://github.com/callezenwaka/motionstream.