An intelligent, agentic AI system that analyzes, explains, and auto-fixes code vulnerabilities β powered by NVIDIA NIM and AWS SageMaker.
CodeGuardian is an AI-powered DevSecOps agent that automatically scans source code, detects security risks, explains vulnerabilities in natural language, and suggests secure fixes.
It combines static analysis (like a linter) with LLM-based reasoning (like an expert security reviewer) β running as an agentic system powered by:
- NVIDIA NIM Inference Microservices
llama-3-1-nemotron-nano-8B-v1β reasoning and fix generationretrieval-embedding-nimβ knowledge retrieval
- βοΈ AWS SageMaker Endpoints for scalable inference
- βοΈ FastAPI backend and lightweight Python agent framework
To make secure software development autonomous, by allowing developers to:
- Upload or scan code automatically.
- Detect insecure patterns and dependencies.
- Get human-like explanations and secure fix suggestions.
- Continuously learn from known vulnerabilities via a knowledge base (KB).
| Feature | Description |
|---|---|
| π Static Code Analysis | Parses Python, JS, and C/C++ code for dangerous patterns, insecure APIs, and secrets. |
| π§ AI Reasoning (NVIDIA NIM) | Uses llama-3-1-nemotron-nano-8B-v1 to explain each issue and propose fixes. |
| π Retrieval-Augmented Knowledge Base | Embeds security best practices (OWASP, CWE) via retrieval-embedding-nim. |
| π¬ Interactive Chat Agent | Allows developers to discuss findings and request clarifications. |
| π§Ύ Risk Summarization | Generates an overall project risk score (Low / Medium / High) with rationale. |
| βοΈ AWS-Ready Deployment | Deployable via Amazon SageMaker or Amazon EKS with Docker support. |
ββββββββββββββββββββββββββββββββ
β Developer β
ββββββββββββββββ¬ββββββββββββββββ
β
βΌ
ββββββββββββββββββββββ
β FastAPI App β
β (app/app.py, /api) β
ββββββββββ¬ββββββββββββ
β
ββββββββββββββββββ΄βββββββββββββββββ
βΌ βΌ
βββββββββββββββββββββββ ββββββββββββββββββββββββ
β Static Analyzer β β Reasoning Engine β
β (agent/parser.py) β β (agent/reasoning.py) β
βββββββββββ¬ββββββββββββ ββββββββββββ¬βββββββββββββ
β β
βΌ βΌ
ββββββββββββββββββββββββ ββββββββββββββββββββββββββ
β Knowledge Store (KB) βββββββΊβ NVIDIA NIM (SageMaker) β
β (FAISS / Embedding) β β Llama-3 + Embedding NIM β
ββββββββββββββββββββββββ ββββββββββββββββββββββββββ
CodeGuardian/
β
βββ agent/
β βββ parser.py # Static analyzer (Stage 2)
β βββ reasoning.py # AI reasoning engine (Stage 3β4)
β βββ aws_client.py # SageMaker integration (Stage 4)
β βββ knowledge_base.py # Seeded security KB
β βββ knowledge_store.py # Retrieval & embedding logic
β βββ persistence.py # Optional SQLite persistence
β βββ **init**.py
β
βββ app/
β βββ app.py # FastAPI app entry
β βββ routes_chat.py # Interactive chat endpoint
β βββ routes_summary.py # Risk summary API
β βββ **init**.py
β
βββ tests/
β βββ test_parser.py
β βββ test_reasoning.py
β βββ test_aws_client.py
β βββ ...
β
βββ input/ # Sample test code files
β
βββ .github/workflows/
β βββ ci.yml # Linting + test pipeline
β
βββ Dockerfile
βββ requirements.txt
βββ .env.example
βββ README.md
git clone https://github.com/<your-username>/CodeGuardian.git
cd CodeGuardianpython -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activatepip install -r requirements.txtCreate a .env file:
AWS_ACCESS_KEY_ID=<your-aws-access-key>
AWS_SECRET_ACCESS_KEY=<your-aws-secret-key>
AWS_REGION=us-east-1
LLM_ENDPOINT_NAME=llama3-nim-endpoint
EMBED_ENDPOINT_NAME=retrieval-embed-endpoint-
Go to AWS Console β SageMaker β Inference β Endpoints
-
Deploy:
llama-3-1-nemotron-nano-8B-v1retrieval-embedding-nim
-
Copy their endpoint names.
aws sagemaker list-endpointsuvicorn app.app:app --reloadThen test:
POST /analyze
Content: { "path": "input/" }
Youβll get JSON output containing:
- Static findings
- AI-generated explanations & fixes
- Risk summary
{
"file": "test_insecure.py",
"findings": [
{
"type": "Hardcoded Secret",
"line": 7,
"severity": "High",
"message": "Avoid hardcoding passwords; use env vars or secret stores.",
"ai_fix": "Replace password with environment variable reference."
},
{
"type": "Insecure Function Usage",
"line": 12,
"message": "Use of eval() can lead to injection.",
"ai_fix": "Remove eval() or validate input properly."
}
],
"overall_risk": "High"
}| Endpoint | Method | Description |
|---|---|---|
/analyze |
POST | Analyze a file/folder for issues |
/summary |
GET | Get project-wide risk summary |
/chat |
POST | Ask questions about issues interactively |
pytest -vCI also runs automatically via GitHub Actions:
- Lint (flake8)
- Unit tests (pytest)
- Optional embedding index build
Build and run locally:
docker build -t codeguardian .
docker run -p 8080:8080 codeguardianAccess: http://localhost:8080/docs
Includes 50+ security patterns and best practices:
- OWASP Top 10
- CWE references
- Python, JS, and C/C++ insecure APIs
- Example fixes and recommended libraries
Stored in agent/knowledge_base.py and indexed via Embedding NIM.
| Area | Stack |
|---|---|
| Language | Python 3.11+ |
| Framework | FastAPI |
| AI Models | NVIDIA NIM (Llama-3, Embedding NIM) |
| Cloud | AWS SageMaker |
| Storage | SQLite (optional) |
| CI/CD | GitHub Actions |
| Containerization | Docker |
| Infra | EKS or SageMaker endpoint deployment |
Want to improve CodeGuardian?
- Fork this repo
- Create a new branch (
feature/add-chat-ui) - Commit your changes
- Submit a pull request π
- Add browser-based chat UI
- Multi-language (Java, Go) analyzers
- Continuous scan mode via GitHub Actions
- Dashboard for risk visualization
- Integration with AWS CodePipeline
Special thanks to:
- AWS & NVIDIA for providing compute and NIM microservices.
- OpenAI & FastAPI for enabling rapid AI backend development.
- OWASP/CWE for the foundational security knowledge base.
"CodeGuardian β making secure coding autonomous, one commit at a time."
This repository includes a lightweight Stage 5 toolkit to help you prepare a clean demo submission:
- Functional tests: run the FastAPI app and exercise
/analyze,/analyze_json,/summary, and/chat(if available). - Offline evaluation: a small script that scans a set of sample files and produces
evaluation/evaluation_results.json. - Lightweight logging: the app writes run-level logs to
logs/app.log.
Quick commands
- Start the server (no --reload recommended for demo):
python -m uvicorn app.app:app --host 127.0.0.1 --port 8000 --log-level info- Run the offline evaluation script (this does not call external LLMs by default):
python scripts/evaluate.pyThe evaluation output will be written to evaluation/evaluation_results.json.
Logging
- App logs are written to
logs/app.log(the folder is gitignored). Each analysis run records a summary line so you can show request history during a demo.
CI
- GitHub Actions runs unit tests; ensure your repository shows a green check on the main/PR to demonstrate stability.
If you want, I can also add a short example post_request.py that calls /analyze_json for the demo, or wire the evaluation script to produce a simple accuracy table (requires manual labels).