Running promptfoo code scans from the CLI

Run promptfoo code scans from the CLI in GitLab, Jenkins or on a developer machine, with the authentication, repository scope and pull request output your team needs.

On this page

When teams run promptfoo code scans from the CLI

Run the promptfoo code scan from the command line when a team wants LLM-specific checks on application code inside an existing pipeline, or on a developer laptop before a change is merged. The CLI scan reads the repository, looks for flaws that are specific to LLM applications, such as prompts built from untrusted input or model output passed into sensitive actions, and reports findings that can gate a merge. It fits teams that already run GitLab or Jenkins and want the check to sit beside their other build steps rather than inside a separate web workflow.

Code scanning is a different control from the other promptfoo features. Red teaming sends adversarial inputs to a running model or application and observes its behavior. ModelAudit inspects model files before they are loaded. Code scanning reads source code and does not test a live endpoint. The promptfoo software runs on your machine and talks directly to the LLM, but the scan itself authenticates with promptfoo credentials, through promptfoo auth login or a PROMPTFOO_API_KEY environment variable. Confirm with your security team where that key is stored and who may create it before the first pipeline run.

Check two prerequisites early. promptfoo is released under the MIT license, so the tool itself can be reviewed and used without a license fee, but the scanning service still requires an account. The npm release requires Node.js 22.22.0 or newer, so confirm that your build images and developer laptops meet that version before you write the job definition. Also confirm, against the promptfoo code scanning CLI documentation, how full-repository scans are launched, since they depend on a pinned filesystem MCP server installed alongside promptfoo.

Which CLI scan option fits each environment

This table compares local runs, GitLab CI and Jenkins for promptfoo code scans across authentication, scan scope, output and API key ownership. Read each row against your own pipeline design. Cells marked to confirm cover steps the CLI documentation does not settle for every platform, so check them with your promptfoo account and CI administrators before you standardize on one option.

Decision factorLocal runGitLab CIJenkins
AuthenticationRun promptfoo auth login, or set PROMPTFOO_API_KEY in the sessionSet PROMPTFOO_API_KEY as a CI/CD variable (confirm masking and protection settings)Pass PROMPTFOO_API_KEY from the Jenkins credentials store (confirm the binding method)
Full-repository scan setupInstall the pinned filesystem MCP server with promptfoo on the machineInstall the pinned filesystem MCP server in the job image or a setup stepInstall the pinned filesystem MCP server on the agent or in a pipeline stage
Scan scopeChosen by the developer at run time (confirm the available scope options)Runs against the checked-out commit (confirm whether changed-files scope is supported)Runs against the workspace checkout (confirm whether changed-files scope is supported)
Output destinationTerminal output (confirm where results appear in your promptfoo account)Job log and results in promptfoo (confirm supported pull request summary posting)Console log and results in promptfoo (confirm supported pull request summary posting)
Who manages the API keyThe individual developer, tied to their own login or shellProject or group maintainers, stored in CI/CD variablesJenkins administrators, held in the credentials store
Key exposure riskKeys can leak through shell history, dotfiles or shared machinesVisible to users who can edit pipelines or variables (confirm scoping for protected branches)Visible to users with job configuration rights (confirm folder and credential scoping)
Best fitDeveloper checks before opening a pull requestGating merge requests in a GitLab projectExisting Jenkins estates with shared pipeline standards

Set up a promptfoo code scan in GitLab or Jenkins

This sequence takes a CI job from a clean runner to a verified promptfoo code scan that posts its summary back to the merge request or pull request. Each step ends with a check so the team knows the scan is authenticated, scoped correctly and reporting before it becomes a gate.

  1. Install Node.js and promptfoo on the runner

    The platform or DevOps engineer who owns the CI runner installs Node.js 22.22.0 or newer, then installs promptfoo from npm. The promptfoo package is published under the MIT license and the npm release 0.124.1 requires that Node.js version or later, so pin both in the job image or setup step rather than relying on whatever the runner happens to have. Check the step by running the Node.js version command and the promptfoo version command in the job log. Both should print versions that meet the requirement before you continue.

  2. Create and store the promptfoo API key

    A team member with access to the promptfoo account creates an API key and stores it as a masked and protected variable in GitLab CI/CD settings or as a secret credential in Jenkins. Limit the variable to the protected branches and projects that run scans, and never place the key in the repository, a job script or a log line. Check the step by confirming the variable appears in the settings as masked and that a test job echoing it prints only a redacted value.

  3. Authenticate the job with promptfoo

    The pipeline authenticates before any scan runs, either by executing promptfoo auth login in the job or by exposing the stored key as the PROMPTFOO_API_KEY environment variable. The environment variable route suits unattended runners because it needs no interactive step. Check the step by running a command that confirms the session is authenticated, and treat any authentication error as a stop condition for the rest of the sequence.

  4. Run a first scan on a test branch

    The engineer creates a test branch containing a known, low-risk change to application code that calls an LLM, then runs the code scan command from the pipeline against that branch. Keep the first run on a branch that is not merged to a protected target so any noise stays contained. Check the step by reading the job log for the scan completion message and confirming the scan reports the files it reviewed, so you know it read the changed code.

  5. Configure the full-repository scan

    Full-repository scans use a filesystem MCP server that is pinned and installed with promptfoo, so the platform engineer confirms that the installation step runs as part of the job and that the server version is pinned rather than floating. Run the full-repository scan on the default branch to establish a baseline of existing findings. Check the step by confirming the log lists every directory the scan covered and that the finding count matches what the team expects from the baseline review.

  6. Confirm the summary reaches the merge request

    Open a merge request or pull request from the test branch and check that the scan summary appears as a comment or status in the review. The job should only report results that the pipeline account can post, so confirm that the CI token has the write permissions the summary step needs. Check the step by verifying the summary text matches the job log, then decide with the security team whether findings should block a merge or only inform reviewers.

  7. Document the setup and the rollback path

    The platform team records the Node.js and promptfoo versions, the variable names, the scan command and the branches the job runs on, then names an owner for updates. Ask the vendor or your own security team to confirm the current posting behavior for your CI system before you enforce it as a gate. Check the step by having a second engineer repeat the setup from the written record on a separate project and reach the same posted summary.

How GitLab, Jenkins and local runs differ in practice

In a GitLab CI job, the scan runs on a runner that your platform team controls, so the job definition and its variables are the main places where configuration lives. The promptfoo code scanning CLI needs promptfoo authentication, either through promptfoo auth login or a PROMPTFOO_API_KEY environment variable, and in a pipeline the environment variable is the usual choice because no interactive login is possible.

  • API key storage: Store the key as a masked, protected CI/CD variable in project or group settings, not in .gitlab-ci.yml, so that it does not appear in the repository history.
  • Node.js version: Pin the image or runner tooling to a Node.js release that meets the promptfoo requirement (22.22.0 or newer), and record that version in the job log so runs stay reproducible.
  • Full-repository scans: Full scans use a pinned filesystem MCP server installed with promptfoo, so confirm that the runner can install it during the job and that outbound access matches your network policy.
  • Result review: Review findings in the job output and any artifacts the job publishes, and check whether summaries are posted back to merge requests in your configuration.
  • Runner isolation: Shared runners serve many projects, so decide whether the API key should be scoped to protected branches only.

Before rollout, confirm the variable scoping, the runner image and the exact summary behavior with your GitLab administrators and the scanning documentation.

Repository content leaves the runner at one clearly marked point

The flow starts with a commit or pipeline trigger that launches a job on a runner with promptfoo and Node.js installed. The runner authenticates with a promptfoo API key, set through promptfoo auth login or PROMPTFOO_API_KEY. It then reads either the changed files or the full repository, where full scans use a pinned filesystem MCP server installed with promptfoo. The labelled trust boundary marks where repository content leaves the runner. Confirm with promptfoo where that content is processed, what is retained, and how the summary is written back to the pull request before enabling scans on private code.

Path from trigger to pull request summary, with the repository trust boundary marked.

Protecting the API key and the code the scan reads

A code scan needs two things protected: the promptfoo credential that authorizes it and the repository content it reads. The cards below cover where the key lives, how narrowly it is used, what leaves your pipeline, and how untrusted merge requests are handled. Confirm each control against the current code scanning CLI documentation before you rely on it.

Store the API key in CI secrets

A scan run authenticates with a promptfoo API key, supplied either through promptfoo auth login or the PROMPTFOO_API_KEY environment variable. In GitLab or Jenkins, keep that value in the platform's masked, protected secret store and never commit it to .gitlab-ci.yml, a Jenkinsfile or a shell script. Check which pipelines and branches can read the variable, because a protected variable is only available to protected refs in GitLab.

Code scanning CLI docs

Limit the key to scan jobs

Scope the credential to the smallest set of projects and jobs that need it, and make sure unrelated build or deploy jobs cannot read it. Ask your team which promptfoo plan and role the key belongs to, and whether it can be issued per pipeline rather than shared across teams. Confirm the permissions a key carries in your account with promptfoo, since the documentation does not describe role granularity for the CLI.

Keep the key out of logs

Verbose debugging, echoed environment variables and failing commands can print the key into job logs, which are often readable by a wide group of developers. Avoid set -x around scan commands, do not print the environment in debug steps, and check the job log after the first run. Treat any key that appears in a log as exposed and rotate it.

Runner isolation for scan jobs

Scan jobs run code from your repository on a runner, so the runner's network access, filesystem and cached state matter as much as the key. Prefer ephemeral or dedicated runners for scans, avoid sharing them with production deployment jobs, and remove workspace artifacts after the job. Confirm with your platform team which runner pools exist and what they can reach.

Repository content sent for scanning

Before rolling out scans, document which files the scan reads and which parts of that content leave your environment for analysis. Full-repository scans use a pinned filesystem MCP server installed with promptfoo, so review what that server can access on the runner and whether it can reach paths outside the repository. Ask promptfoo to confirm, in writing, where analysis runs and how code is retained.

Forked and external merge requests

Merge requests from forks or external contributors can contain changes designed to read secrets or alter scan configuration. Decide whether scans run on untrusted contributions at all, and if they do, do not expose the API key to those pipelines. Confirm how your GitLab or Jenkins setup handles fork pipelines and pull request triggers before enabling automatic scans.

Rotate the key on a schedule

Plan rotation before the first rollout so that replacing a key does not break every pipeline at once. Record which pipelines use each key, rotate on staff changes and after any suspected exposure, and confirm with promptfoo how keys are revoked and reissued. Test the rotation on a non-production project first.

Questions teams ask before running promptfoo code scans

What drives the cost of running promptfoo code scans from the CLI?

Cost is mostly the people time to wire scans into your pipelines, plus any runner capacity you add. Effort rises with the number of pipelines that need a scan, the size of each repository, the number of environments (for example, separate development, staging and production projects), and how secrets are handled. Scans that run on full repositories take more time to configure and review than scans limited to changed files. A written quote should break out pipeline count, repositories in scope, environments, secret storage approach and whether a retest is included. Ask whether any cost recurs, such as ongoing maintenance of pipeline templates when Node.js or promptfoo versions change.

How long does a first promptfoo code scan rollout usually take?

The first rollout usually takes longer than each later pipeline because it includes access setup, secret handling, a test run on a non-production branch and agreement on how results are reviewed. Duration depends on how many repositories and pipelines are involved, how quickly your team can grant repository and runner access, and how many approval steps your change process requires. Agree a timeline in the written scope rather than relying on a general estimate, and ask the provider to list the milestones: access, a working scan, full-repository coverage and handover.

What does our internal team need to provide before a scan runs?

Your team needs to provide a few prerequisites before the first scan runs:

  • A CI runner (GitLab or Jenkins) with Node.js 22.22.0 or newer, the minimum version for the current promptfoo release.
  • A promptfoo API key set as PROMPTFOO_API_KEY in a protected secret store, or an interactive sign-in through promptfoo auth login for local runs.
  • Read access to the repositories in scope and permission to post summaries to merge requests or pull requests.
  • Network egress from the runner to the promptfoo service, which your network team should confirm against the official documentation.

Also confirm who owns the secret rotation and who may approve changes to the pipeline configuration.

Can our own engineers set up promptfoo code scans without outside help?

Yes, a team with CI experience can set up promptfoo code scans alone, because the CLI setup is documented and the steps are the same as other pipeline jobs. The harder parts are usually the ones outside the tool: secret handling, runner configuration, deciding what counts as a blocking finding, and agreeing how developers respond to results. Teams that lack staff for those decisions, or that need the setup reviewed by their security function, often bring in a partner for the scope and review. DeployOpen plans, implements and documents this kind of setup in infrastructure you control, under a written scope.

Do promptfoo Community and Enterprise plans change how CLI code scans work?

Confirm the current entitlements on the promptfoo pricing page before you plan, because plan contents can change. The Community edition is free and includes LLM evaluation and red teaming with a monthly probe allowance and community support. Enterprise adds team sharing, access control and SSO, centralized dashboards, remediation recommendations and priority support, at custom pricing. Ask the vendor which plan your CLI scans authenticate against, how scans are attributed to teams and whether any of these features affect your pipeline. Pricing is not published as a fixed list, so the answer should come from a written quote.

Does promptfoo On-Premise change the code scanning path?

It can, and you should confirm the exact path before design. promptfoo On-Premise runs Enterprise functionality on your own infrastructure with data isolation and a dedicated deployment engineer, so the place your scan results are stored and the endpoint your CLI authenticates against may differ from the hosted service. Ask the vendor which endpoint and authentication setting the CLI uses in an On-Premise deployment, how scan data leaves or stays inside your network and how upgrades are handled. Your security team should review that data flow before the pipeline is approved.

What should we check about scan data and secrets before the first run?

Check what code context leaves your network, where the promptfoo API key is stored, and who can read pipeline logs. The API key should live in a protected CI variable or secret manager, never in the repository, and it should be scoped and rotated under your normal process. For full-repository scans, the CLI uses a pinned filesystem MCP server installed with promptfoo, so confirm the version pin and that the server only reads the paths you intend. Write these checks into the scope so the security review has evidence before the first merge request is scanned.

When a CLI scan is the wrong choice for your team

A CLI scan is the wrong choice when your team does not want to own the scanner's credentials and runner upkeep. Running promptfoo code-scans run yourself gives you control over which runner executes the scan, when it runs and what it can reach, but it also means your team issues and rotates the promptfoo API key, stores it as a masked CI variable, keeps the Node.js runtime current on the runner (the current npm release requires Node.js 22.22.0 or newer) and watches the pipeline when the scanner changes. If nobody on your platform team wants that work, a managed integration will likely cost less attention. Teams already on GitHub may find the GitHub App path, covered in a sibling topic, a better fit, since it removes most of the pipeline wiring. Confirm with your own engineers how much pipeline maintenance they can absorb before choosing.

Identity and data location need a decision before a CLI scan spreads across many repositories. The scan authenticates with promptfoo auth login or a PROMPTFOO_API_KEY, so every key is a credential that can be shared, leaked or left behind when someone leaves. Self-hosted promptfoo is not recommended for production use: its SQLite database cannot be shared across replicas, and it has no RBAC, horizontal scaling, built-in authentication or SSO. If your policy requires SSO and role-based access to scan results, the Enterprise or On-Premise editions are the path the vendor describes, and you should confirm their terms directly with promptfoo before you scale. Write down where source code leaves your network and who can see findings before the first full-repository scan.

How DeployOpen scopes and supports promptfoo code scan rollouts

A promptfoo code scan rollout touches your repositories, CI runners, credentials and pull request workflow, so the scope needs to be agreed before anything is configured. DeployOpen fixes the scope in writing, builds and tests the scan in your pipelines, then hands over a runbook and optional ongoing support. The cards below cover each step and what you should confirm before work starts.

Agree scope in writing first

The scope names the repositories to scan, the CI systems involved (GitLab, Jenkins or local runs), the branches and pull requests that trigger scans, and the deliverables. Because the CLI needs a promptfoo API key and a full-repository scan depends on a pinned filesystem MCP server, both belong in the agreed scope. Ask for a written list of repositories and pipeline owners before any quote is finalized.

Authentication and secret handling

Decide how the promptfoo API key reaches the job: an interactive promptfoo auth login for local runs, or a PROMPTFOO_API_KEY variable stored as a masked, protected CI secret. Confirm who owns the key, how it is rotated when a person leaves, and that job logs never print it. DeployOpen configures and tests these paths in your CI so the key is never stored in the repository.

Code scanning CLI docs

Full-repository scan setup

Full-repository scans rely on a filesystem MCP server that is pinned and installed with promptfoo. Pinning matters because an unpinned server can change behavior between runs. DeployOpen sets the version, installs it in your build image or runner, and records how to update it. Confirm that runners can reach the required services and that the image policy allows the install.

Pull request summaries and gating

Define what the CI job posts back to the pull request, which findings block a merge, and which only annotate it. Teams often start in report-only mode and tighten thresholds later. DeployOpen tests the comment path on a sample branch and checks how the job behaves when the scanning service is unreachable, so failures are visible rather than silently passing.

Testing in your pipelines

Scans are configured and tested inside your own CI, using your runners, network rules and branch protection. Testing covers a clean run, a run that should fail, a full-repository scan, and a pull request from a fork if your policy allows forks. Ask which environments are production-like and which are only for trial runs before testing begins.

Runbook and handover

The runbook documents the pipeline definitions, secret locations, the pinned MCP server version, the upgrade steps, and how to triage a failed or noisy scan. It is written for the platform and security engineers who will run the scan after handover. Ask for the runbook format and review rights before work starts, and confirm who signs off on the final version.

Retainers for upkeep and upgrades

Ongoing work includes updating the promptfoo CLI and the pinned MCP server, reviewing new findings policy, and fixing pipeline breakage when runners or CI versions change. These are separate from the initial scope and are offered as retainers. DeployOpen does not publish prices. A quote follows from the written scope, so ask for recurring tasks and response expectations to be listed separately from one-time setup.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.