Running PyRIT scans in CI/CD pipelines to catch regressions before release
A team shipping model, prompt or agent changes needs red teaming that repeats on every build, not only at the end of a quarter. pyrit_scan can run as a pipeline step against a registered target, so each candidate build is tested against the same scenario and the result can gate a release. PyRIT is an open source framework from Microsoft under the MIT license, and pyrit_scan is one of its three usage modes, alongside CoPyRIT for human-led testing and the Python framework for custom attacks.
A CI/CD scan answers a narrower question than a full assessment. A full quarterly assessment covers the harm categories, techniques and datasets your risk owners care about, and it produces evidence for reviewers. A pipeline scan is a small, fixed scenario that checks whether a specific change, such as a new system prompt, a model version swap or a new tool for an agent, has reopened a known weakness. Teams usually need it when several people change model-facing behavior often, when a release is gated on safety review, or when a regression would reach customers before the next scheduled assessment. The pipeline scan does not replace the assessment; it catches the regressions that would otherwise wait for it.
Confirm three things before you add the step. First, the scenario and its dataset size must finish in a time your pipeline tolerates, so start with a limited dataset and check the run time. Second, the target must be registered in a configuration the runner can read, and the credentials for it must come from a shared store rather than a file copied onto each agent. Third, decide who reviews a failed gate and what the threshold means, since a scorer result is a signal to triage, not a verdict. Ask your platform team which runner type will execute the job, because that choice determines where secrets and logs live.
Request and secret flow for a pipeline scan
The flow starts when the CI runner job begins and reads its configuration from Azure Key Vault, which is PyRIT's canonical source for shared and pipeline settings. The runner then invokes pyrit_scan inside its own trust boundary, and the requests cross into the system under test through the registered target. Responses go to the scorer and results are written to memory storage, while only the pipeline results artifact leaves the job. Check that the runner's identity can read only the secrets the scan needs, that the target sits on the far side of the boundary, and that attack prompts and responses are not echoed into job logs.
How secrets, attack traffic and results move through a pipeline scan.
Keeping each pipeline scenario small enough to run on every change
A PyRIT scan in a pipeline only stays useful if it finishes fast enough to run on every change. The cards below cover how to narrow the scenario, cap the first dataset, pick techniques that match the change, and decide which builds get a full scan.
Choose a narrow scenario
Start by matching the scenario to the component that changed, rather than running every packaged assessment on each build. A prompt template change calls for a different scenario than a change to retrieval or tool access. Keep one scenario per pipeline job so a failure points to a specific harm category. Confirm the scenario names and what each one covers with pyrit_scan listing output in your own environment before wiring them into CI.
Cap the dataset for first runs
A pipeline scan should start with a small, fixed number of objectives so the job has a predictable size. Set the dataset limit in the job definition and record it alongside the build so results can be compared across runs. Increase the limit only in scheduled or release-level scans. Measure runtime and request counts on your own target before setting any timeout, because they depend on your model, rate limits and endpoint latency.
Select techniques that fit the change
Single-turn techniques are cheaper and faster than multi-turn attacks that use an adversarial model across several exchanges. For a change to a system prompt or a single model setting, single-turn coverage often answers the question. Reserve multi-turn strategies for changes that affect conversation state, memory or tool use. Document the technique set per job so reviewers can see why a given scan was narrow.
Split smoke and full scans
Use a smoke scan on feature branches and merge requests, and a full scan on release candidates, main branch builds or on a schedule. The two job types should share one configuration file so the only difference is scope. Make the full scan a required gate before release, and keep the smoke scan advisory unless your change policy says otherwise. Confirm with your risk owner which builds count as release builds.
Set a budget for each job
Each job needs an agreed ceiling on runtime and on model requests, since both drive cost on a paid endpoint. Track how long the smoke scan takes across several builds, then set the timeout with headroom above that baseline. If a scan exceeds the ceiling, fail the job with a clear message instead of letting it hang on a shared runner. Ask your platform team who pays for model calls made by pipeline jobs.
Pipeline configuration options and when each fits
This table compares four ways to supply PyRIT configuration to a pipeline: Key Vault, a plaintext file on one runner, pipeline-scoped variables and per-environment targets. Read each row against your runner model and how many people can reach the job logs. Key Vault is the option PyRIT names as its canonical source for shared and CI/CD configuration, and the plaintext file remains supported but triggers a PyRIT warning.
| Option | Where it lives | Fits when | Trade-off |
|---|---|---|---|
| Azure Key Vault | Secrets in an Azure Key Vault, read by the job at run time | Shared or hosted runners that many pipelines use, and teams that need access logged and revoked centrally | Needs a managed identity or service principal for the runner and Key Vault access policies maintained |
| Plaintext ~/.pyrit/.env on one runner | A file in the home directory of a dedicated, trusted runner | A single self-managed runner that only your team uses and that is locked down at the host level | PyRIT warns that plaintext files are less secure; a compromised runner exposes every credential in the file |
| Pipeline-scoped variables | Masked or protected CI/CD variables defined in the pipeline or project settings | Small projects with few secrets and one owner who controls who can edit pipeline settings | Secrets are copied into each project, rotation is manual, and masking does not stop all leakage into logs |
| Separate targets per environment | Distinct target registrations for development, staging and release endpoints | You need to test a pre-release model or endpoint that must never receive production traffic from CI | More targets and credentials to maintain, and each one still needs its own secret source |
| Build-specific memory labels | Labels attached to each run in PyRIT memory, not in credentials | You need to trace which build produced each result during review or audit | Labels do not protect secrets; pair them with one of the options above |
Setting up pyrit_scan in a CI pipeline
This sequence takes a pipeline from an empty runner to a scheduled pyrit_scan run that reads its secrets from Key Vault, labels its results per build, and leaves a checkable exit status and stored record behind. Each step closes with a check the platform or security team can repeat.
Confirm the Python version on the runner
The platform engineer confirms the CI image provides a Python version that the PyPI package supports, which is 3.10 up to but not including 3.15. The PyRIT documentation recommends Python 3.13, so pin that version in the runner image or the job's setup step if the shared image differs. Verification: a job step that prints the interpreter version shows a supported release, and the job fails early if it does not.
Install PyRIT from PyPI in the job
The pipeline installs the pyrit package from PyPI into a clean virtual environment, not a shared site-packages directory, so each build records which version it ran. Pin the version in a requirements file or lock file that the security team reviews, and record the release notes for any version change. Verification: the job runs pyrit_scan with a help or list command and exits successfully before any target is contacted.
Register the target in the pipeline configuration
The engineer who owns the application under test registers its target so pyrit_scan can address it by name, whether that is a hosted model endpoint, a custom HTTP endpoint or a web app driven through Playwright. The registration names the target, not its credentials, so it can be committed to the repository. Verification: a target listing command run in the job shows the target by name, with no secret values printed.
Store secrets in Azure Key Vault and grant read access
The cloud or security administrator places the target's API keys and connection strings in Azure Key Vault, which the PyRIT documentation names as the canonical environment source for shared and CI/CD configuration. The runner's managed identity or workload identity receives read access to only those secrets. Verification: a test step retrieves one secret by name and reports only its length, and a second identity without the role is refused.
Add the .pyrit_conf settings for the runner
The engineer adds a .pyrit_conf file with the non-secret settings the scan needs, such as memory location, concurrency and the Key Vault reference, and keeps plaintext ~/.pyrit/.env files off shared runners because PyRIT warns that they are less secure. Review the configuration keys against the PyRIT configuration file documentation for the version you pinned. Verification: a dry run loads the configuration and reports which sources resolved, with secret values masked in the log.
Set a memory label for each build
The pipeline passes a label built from the pipeline ID, commit and target name into the scan, so every conversation and result in memory can be traced to one build. The label should identify the run without containing attack content or secrets. Verification: a query against memory after the run returns records carrying the expected build label, and records from another build do not appear under it.
Run a small scenario as the pipeline gate
For each change, the pipeline runs a deliberately small scenario against the registered target, with a limited dataset size, so the job finishes in a time the team accepts and failures stay readable. The team decides which scenario and techniques are the gate, and records that choice in the pipeline definition for review. Verification: the job completes against the target and writes results to memory without exceeding the configured concurrency.
Check the exit status and stored results
The pipeline reads the exit status of pyrit_scan and fails the build on a non-zero exit, then keeps the stored results as a pipeline artifact or in a store the security team can query, and keeps attack prompts out of the job log. Confirm which results are retained and for how long with your own policy, since the facts supplied do not set a retention period. Verification: a deliberately failing target produces a red build, and the stored results list the build label without printing prompt text in the log.
Memory labels and results per build
Every pipeline run should write its results with labels that identify the build, commit, branch and pipeline that produced them. PyRIT's memory stores conversations and results in SQLite or Azure SQL, so labels set at run time are what let a later reader connect a finding to a specific change. Without them, a shared memory store holds many runs that look alike.
- Build identifier: Pass the CI job or pipeline ID so each run can be found from the build page.
- Commit SHA: Record the exact revision under test, since branch names move.
- Scenario name: Keep the scenario and its version in the label so runs of different scenarios stay separate.
- Target name: Record which registered target was tested, especially when staging and production targets share a pipeline.
- Stable label keys: Agree on key names with the security team so queries work across all pipelines.
Confirm with your PyRIT version how labels are passed at run time and which fields are stored in your memory backend before you rely on them for review.
When a release is under review, the team needs to pull every PyRIT run tied to that build or to a set of commits. Querying memory by label answers questions such as which scenarios ran against a release candidate, which objectives succeeded, and whether a later build repeated an earlier failure. The query path should be tested before an audit or sign-off depends on it.
- Release mapping: Keep a record that maps each release tag to the pipeline runs and commit SHAs it included.
- Export for review: Export the conversations and scores for the flagged runs so reviewers do not need database access.
- Regression checks: Compare the same scenario across two builds to see whether a finding was fixed or reappeared.
- Access during review: Limit query rights to the people who need them, since stored prompts and responses can contain harmful content.
- Query tests: Run a sample query on a test release to confirm the labels return the expected records.
Ask the PyRIT maintainers or your own engineers to show a release query on a sample run before the first release gate uses it.
Memory records hold attack prompts, model responses and scores, so they are sensitive records in their own right. How long to keep them, where they sit and when they are deleted must be decided by the client, usually with legal, privacy and security owners. DeployOpen can help configure the storage and the purge job, but the retention period itself is a policy decision for your organization.
- Retention owner: Name the person or group who sets and approves the retention period.
- Storage location: Decide whether SQLite files on runners or an Azure SQL database holds the records, and where backups go.
- Purge process: Define how records are deleted, including backups and exported files, and how deletion is logged.
- Legal holds: Plan how records tied to an open finding or audit are kept beyond the normal period.
- Runner cleanup: Make sure ephemeral CI runners do not leave local memory files behind after a job ends.
Confirm your organization's retention and access requirements in writing before the pipeline is enabled on shared runners.
Keeping attack content out of job logs
Red team prompts, model responses and scorer verdicts can contain harmful content, sensitive data or leaked credentials, and a CI job log is often readable by far more people than the team running the test. The cards below cover the controls that keep this material in restricted storage rather than in build output, and each one should be confirmed against your own CI platform's documentation.
Mask secrets in runner output
Configure your CI platform to mask the values of Azure Key Vault secrets and any API keys PyRIT loads at runtime, so they do not appear in plain text if a verbose flag or stack trace prints them. Masking usually works only on exact string matches, so a key that is base64-encoded or split across lines can still leak. Check the masking rules in your runner documentation and test them with a deliberately printed dummy value.
Avoid echoing prompts and responses
Keep pyrit_scan output at a summary level in the pipeline, and do not add shell echo or debug prints of objectives, converted prompts or model replies. A single harmful response printed to stdout is copied into the job log, the log archive and any notification that quotes it. Review any wrapper script or custom scenario for print statements before it runs on a shared runner.
Store conversations in restricted memory
Point PyRIT memory at a database that only the scanning service identity and named reviewers can read, rather than letting full transcripts land in the build log. Use per-build memory labels so reviewers can query a specific run. Confirm who can read the SQLite file or Azure SQL database, how long rows are kept and how they are deleted.
Restrict artifact visibility
Build artifacts such as result files, exported conversations or HTML reports should be scoped to the project members who need them, not to every user who can view pipeline runs. Check whether artifacts are downloadable by anonymous or read-only users, how long the platform keeps them and whether they are included in cached or mirrored outputs.
Review third-party log forwarders
Many organizations forward CI logs to a SIEM, a log platform or a chat integration, and each forwarder creates another copy of anything printed. Inventory every forwarder attached to your runners and pipelines, confirm what it captures and where it stores it, and decide whether attack content should be excluded from forwarding entirely. Ask the forwarder vendor how it handles retention and access.
Questions teams ask before running PyRIT in CI/CD
What does it cost to run PyRIT scans in CI/CD?
PyRIT is open source under the MIT license, so the software itself carries no license fee. The cost is the work and the infrastructure: engineering time to design the scenario, wire the pipeline, set up Azure Key Vault and runner identity, and review findings, plus the compute and model endpoint calls each scan makes. Model calls recur with every run, so the scenario size and trigger frequency drive the bill more than anything else. Ask any partner for a quote that separates one-time setup from recurring run costs and states which model endpoints and runner types are assumed. DeployOpen quotes follow from a written scope.
How long does setting up a PyRIT pipeline take?
Duration depends on how many targets and pipelines are involved, how mature your Key Vault and runner setup is, and whether a custom scenario is needed. A single pinned, small scenario on one target is a much smaller job than a shared, multi-team setup with per-build memory labels and access reviews. Confirm the Python version you will pin, since the PyPI package supports Python 3.10 up to but not including 3.15 and the documentation recommends 3.13. Your scope document should state the timeline once the target list and runner model are known.
What does the team need to provide for the work?
The team needs an owner for the target endpoint, access to a Key Vault where model credentials can be stored, and permission for the pipeline identity to read only the secrets it needs. You also need someone who can decide what a failing scan means for a release, and who reviews the results. Engineers should be ready to pin PyRIT and dependency versions and to test the scenario against a non-production target first. Ask for a list of required access before work starts so security can approve it in one pass.
Can our own team build this without a partner?
Yes, if you have engineers comfortable with Python, your CI system and Azure Key Vault. PyRIT installs with pip and its documentation covers configuration, so a capable team can build a basic pipeline. Teams usually bring in a partner for the parts that are easy to get wrong: keeping attack content out of job logs, scoping runner identity, deciding which scenario gates a release, and documenting the evidence. Compare your team's capacity against those items before deciding.
How do GitLab or other runners change the design?
The runner type decides where secrets live, how identity is granted, and whether logs are shared. Shared runners are used by many projects, so configuration must come from Key Vault at run time rather than from files on the runner host, and job logs must never echo prompts or model responses. Self-hosted runners give you more control but need hardening and patching. GitLab's documentation covers its runners, and self-managed GitLab can run in offline environments, which matters if your scans must stay inside a restricted network. Confirm your runner model before choosing the secret pattern.
Does a per-change scan replace a full red teaming assessment?
No. A small scan on each change catches regressions in a narrow set of objectives, which is useful for release gating. It does not establish the overall risk posture of the system. Full assessments use wider datasets, more techniques and human review of findings, and they run on a schedule or before major launches. Treat the per-change scan as one control within a broader program, and agree in writing which evidence each layer produces before you cite either in a compliance review.
Where do the scan results go, and who can read them?
PyRIT stores conversations and results in SQLite or Azure SQL, so the storage location determines who can query them. Per-build memory labels let you trace a result back to a specific build, but the stored prompts and responses may contain harmful content, so access should be restricted to the people who review findings. Confirm where memory is written on shared runners, how long it is kept and who holds access before the first scan runs against production-like endpoints.
Security and operational considerations for shared runners
A PyRIT scan in a pipeline touches a live model, a credential store and a memory database that holds attack prompts and responses. The cards below cover the controls that keep those pieces contained on runners shared by several teams, and the operating costs that grow with every build.
Isolate the runner that runs attacks
A PyRIT job sends adversarial prompts to a target and writes the responses to disk, so the runner executing it should not be the same machine that builds or deploys production code. Ask who else can read the runner's workspace, cache and job artifacts between builds. Use ephemeral or single-job runners where your CI platform supports them, and confirm that one team's scan cannot read another team's memory database or configuration.
GitLab Runner docsScope Key Vault access per pipeline
Azure Key Vault is PyRIT's canonical source for shared and CI/CD configuration, so the identity a runner uses to read it defines what an attacker who compromises a job can reach. Give each pipeline or environment its own identity with read access only to the secrets its target needs. Confirm that the identity cannot list or read the secrets for unrelated targets or production systems.
Rotate target credentials on a schedule
Model API keys and endpoint secrets used by a scan are often copied into several pipelines and forgotten. Record which secret each pipeline reads, who owns it and when it was last rotated, then rotate on a fixed cadence and after any runner incident. Check that a rotated secret takes effect on the next build without editing pipeline files, so rotation does not stall releases.
Protect the memory database
PyRIT memory stores conversations and scoring results in SQLite or Azure SQL, and that record contains the attack prompts and the target's harmful outputs. Decide where each build's database lives, who can read it, and how long it is kept before the job finishes. Restrict artifact download permissions on the CI platform, and treat exported memory with the same handling rules as the findings it supports.
Report PyRIT vulnerabilities privately
If a scan exposes a flaw in PyRIT itself, such as a credential leak through its logging or a defect in its configuration handling, report it through the Microsoft Security Response Center under the project's security policy rather than opening a public issue. Put that channel in your pipeline runbook so engineers know where to send it. Confirm the current reporting steps in the project's security policy before you rely on them.
Budget for target calls on every build
Every build that runs a scan sends prompts to a paid model endpoint, and multi-turn techniques send several requests per objective. Cost is paid to the model provider and to whoever runs the runners, and it recurs with each commit. Ask for a per-build request estimate from your scenario size, cap the dataset for pull requests, and keep the full suite for scheduled or release runs.
Trade-offs of per-change scans versus scheduled full runs
A per-change scan and a scheduled full assessment answer different questions, so the pipeline should not force one to do the other's job. A small scenario on every change gives developers feedback while the change is still fresh: a prompt template edit, a system prompt revision or a new tool wiring can regress safety behavior, and a narrow run against a fixed slice of objectives will catch many of those regressions before merge. The price is coverage. A small slice of prompts cannot show that the application is safe across the harm categories your organization cares about, and a pass on a narrow scenario should be read as "no obvious regression in this slice," not as a clean bill of health.
Scheduled full runs buy breadth. A wider scenario set, more techniques and larger datasets take longer and consume more model calls, and that cost recurs every time the schedule fires, so the cost drivers are the scenario size, the number of target and adversarial model calls and how often you run it. Ask your team to estimate those call volumes from the scenario configuration before setting the schedule, and confirm the model provider's rate limits and billing terms for the account the runner uses. A nightly or weekly full run against the main branch, with results stored in PyRIT memory under a clear label, gives you a trend line that a single build cannot.
A release gate makes sense when a failed assessment should block a deployment, and it works best when the gate is defined before anyone needs to argue about it. Set the threshold, the scenario and the owner who can accept a documented exception in advance, and keep the gate for the release path rather than every commit. Run the per-change scan on merge requests for fast signal, the scheduled full run for drift, and the gate on release candidates, so each stage answers one question and a team can explain to auditors which evidence supported each decision.
How DeployOpen scopes and delivers PyRIT pipeline scans
DeployOpen plans and builds PyRIT scans for CI/CD pipelines inside the infrastructure you control, starting from a written scope that fixes which scenario runs on which change and where its configuration lives. We build the pipeline job, the Key Vault configuration path and the memory labelling, then test that attack content stays out of job logs before handing the setup to your team.
How we scope
- Agree in writing which applications, targets and pipeline stages the PyRIT scan covers
- Define the small scenario each change triggers and the dataset size limit for a first run
- Confirm where shared runners, secrets and memory storage sit within your infrastructure and access model
How we build
- Build the pipeline job that calls pyrit_scan against a registered target on each change
- Wire configuration to Azure Key Vault and check that no plaintext ~/.pyrit/.env file is used on shared runners
- Apply a memory label per build and test that prompts, responses and scorer output are kept out of job logs
How we hand over
- Deliver the pipeline definition, scenario configuration and Key Vault setup with a short runbook for your engineers
- Document the failure behavior, retry settings and how to read results from a failed or partial run
- Walk your team through reviewing memory records and rotating credentials used by the job
How we support
- Offer ongoing upgrades and continuous testing of the pipeline scans as a retainer, if your team wants it
- Retest the pipeline after PyRIT version changes or changes to the targets it scans
- Confirm with us in the written scope which support level and response terms apply to your environment

