AI workflows are increasingly integral to business-critical operations, but they also introduce unique security risks—from data leakage to model manipulation. Manual security audits are time-consuming and error-prone. In this Builder’s Corner tutorial, you’ll learn how to automate AI workflow security audits using open-source tools. This guide walks you through setting up a reproducible, scalable pipeline to continuously scan your AI workflows for vulnerabilities, compliance gaps, and misconfigurations.
If you’re looking for a broader review of the top solutions in this space, check out our Best Tools for AI Workflow Security: 2026’s Leading Platforms Reviewed.
Prerequisites
- Operating System: Linux (Ubuntu 22.04+) or macOS (Monterey+); Windows with WSL2 is also supported
- Python: 3.10 or higher
- Docker: 24.0+ (for container-based scanning)
- Git: 2.30+
- Familiarity with: Terminal/CLI basics, YAML configuration, and AI workflow orchestration (e.g., Prefect, Airflow, or Kubeflow)
- Sample AI workflow: This tutorial uses a Prefect-based workflow, but the approach applies to other orchestrators
Step 1: Set Up Your Sample AI Workflow
-
Clone a Prefect-based AI workflow repository:
git clone https://github.com/PrefectHQ/prefect-recipes.git
cd prefect-recipes/ai-workflows/sample-pipeline
Description: The sample pipeline includes a simple data preprocessing and model training flow using Prefect.
-
Create a virtual environment and install dependencies:
python3 -m venv venv source venv/bin/activate pip install -r requirements.txtTip: Replace
requirements.txtwith your actual requirements file if customizing.
Step 2: Choose and Install Open-Source Security Audit Tools
We’ll use three open-source tools to cover different threat vectors:
- Bandit: Python code security analysis
- Trivy: Container and dependency scanning
- Checkov: Infrastructure-as-Code (IaC) security scanning (YAML, Terraform, etc.)
-
Install Bandit:
pip install bandit
-
Install Trivy:
brew install aquasecurity/trivy/trivy # macOS sudo apt-get install -y wget wget https://github.com/aquasecurity/trivy/releases/latest/download/trivy_0.50.0_Linux-64bit.deb sudo dpkg -i trivy_0.50.0_Linux-64bit.deb # Ubuntu -
Install Checkov:
pip install checkov
Step 3: Scan Your AI Workflow Source Code for Vulnerabilities
-
Run Bandit on your workflow codebase:
bandit -r . -o bandit_report.txt -f txt
This command recursively scans all Python files in the current directory and outputs a human-readable report to
bandit_report.txt.
-
Review and address critical issues:
cat bandit_report.txt | grep "HIGH"
Look for issues such as hardcoded secrets, unsafe YAML loading, or insecure subprocess usage. Fix these in your codebase.
Step 4: Audit Container Images and Dependencies
-
Build your workflow’s Docker image (if applicable):
docker build -t ai-workflow:latest .
Description: This creates a local image for Trivy to scan. If you use a different tag or registry, adjust accordingly.
-
Scan the image for OS and Python package vulnerabilities:
trivy image ai-workflow:latest --format table --output trivy_report.txt
Trivy will flag outdated packages, known CVEs, and misconfigurations in your container image.
-
Scan for secrets in your repository:
trivy repo . --scanners secret --output trivy_secrets.txt
This helps catch hardcoded API keys or credentials accidentally committed to your repo.
Step 5: Scan Infrastructure-as-Code (IaC) for Security Risks
-
Run Checkov on your workflow’s infrastructure definitions:
checkov -d . --output json --output-file-path checkov_report.json
This scans YAML, Kubernetes manifests, Terraform, and other IaC files for security misconfigurations relevant to AI pipelines.
-
Filter for failed checks:
cat checkov_report.json | jq '.results.failed_checks[] | {file_path, check_name, guideline}'Requires
jqfor JSON parsing. Focus on failed checks related to access controls, network exposure, and data encryption.
Step 6: Automate Security Audits With a CI/CD Pipeline
Integrate these tools into your CI/CD workflow for continuous security coverage. Here’s a GitHub Actions example that runs Bandit, Trivy, and Checkov on every pull request:
name: AI Workflow Security Audit
on: [pull_request]
jobs:
security-audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
pip install bandit checkov
- name: Run Bandit
run: bandit -r . -o bandit_report.txt -f txt
- name: Install Trivy
run: |
sudo apt-get install -y wget
wget https://github.com/aquasecurity/trivy/releases/latest/download/trivy_0.50.0_Linux-64bit.deb
sudo dpkg -i trivy_0.50.0_Linux-64bit.deb
- name: Build Docker image
run: docker build -t ai-workflow:latest .
- name: Run Trivy
run: trivy image ai-workflow:latest --format table --output trivy_report.txt
- name: Run Checkov
run: checkov -d . --output json --output-file-path checkov_report.json
- name: Upload Reports
uses: actions/upload-artifact@v3
with:
name: security-reports
path: |
bandit_report.txt
trivy_report.txt
checkov_report.json
Description: This workflow ensures every code change is automatically audited for security risks before merging.
Common Issues & Troubleshooting
-
Bandit/Checkov not finding files: Ensure you’re running the tools from the root of your workflow repo. Use
bandit -r .orcheckov -d .. -
Trivy Docker image build fails: Double-check your
Dockerfileand make sure Docker is running. Usedocker ps
to verify. -
False positives: All tools may flag issues that aren’t exploitable in your context. Suppress or ignore these using tool-specific configuration (e.g.,
.banditor.checkov.yml). -
CI/CD pipeline timeouts: Large images or codebases can slow down scans. Use
--skip-pathor--excludeflags to omit irrelevant directories. -
Permissions issues: Some scans (especially Trivy) may need elevated permissions. Run with
sudoif necessary, but avoid in production pipelines.
Next Steps
Congratulations! You’ve set up a reproducible, automated pipeline to audit AI workflow security using open-source tools. This approach can be extended to more complex workflows and integrated with notification systems (Slack, email) or policy engines (OPA, Kyverno).
- Explore advanced orchestration and compliance automation with our guide on building automated AI compliance workflows in financial services.
- For custom orchestration, see how to build a custom AI workflow with Prefect.
- Consider when to add human-in-the-loop interventions for critical AI automations.
- For a broader comparison of tools, revisit our Best Tools for AI Workflow Security: 2026’s Leading Platforms Reviewed.
Automating security audits is a key step toward robust, trustworthy AI operations. Keep your tools and dependencies up to date, review audit reports regularly, and iterate on your pipeline as threats evolve.