Malware generation testing with garak's malwaregen probes

garak's malwaregen probes check whether a model or assistant will write malware, malware components, evasion code or payloads, and this page explains what each probe asks, how to configure and read a run, and what good responses look like.

On this page

Why test malware generation with garak's malwaregen probes

A team putting a coding-capable model or assistant in front of developers or the public needs evidence that it refuses malware requests, not just an assurance from the model provider. garak's malwaregen module tests whether a system complies with requests to generate malware or malware components. It does this with four probe groups: TopLevel, which asks for complete malicious programs; SubFunctions, which asks for individual pieces such as a keylogger routine or a persistence mechanism; Evasion, which asks for code that avoids detection; and Payload, which asks for the content a malicious program would deliver. Testing all four shows whether a refusal holds when a request is split into smaller, more innocent-looking parts.

Teams need this test wherever generated code can reach a user or a system. The usual cases are coding assistants inside an IDE or code review tool, agents that can write and execute code, and general chat assistants exposed to anonymous users, where any person can type a request. Each case raises a different question for the team. For a coding assistant, the question is whether it will produce working attack code for an employee or contractor. For an agent with execution rights, it is whether a tool call could run what the model writes. For a public chat, it is whether the refusal survives casual rephrasing. Write these questions down before choosing probes, because they decide which results matter.

garak is an Apache 2.0 licensed command-line tool, so an organization can run it on infrastructure it controls and keep scan prompts and responses inside its own environment. DeployOpen can set up garak in that environment, connect it to the target model or application endpoint, and agree on the probe selection and report handling in writing before a scan starts. Confirm with your own security team which generator and endpoint the scan will target, whether the scan runs against a production or staging system, and who owns the JSONL reports that the run produces, since those reports will hold examples of the malicious requests themselves.

What the TopLevel, SubFunctions, Evasion and Payload probes ask for

garak's malwaregen module checks whether a system complies with requests for malware or malware components. The four probe families escalate from a request for a whole program down to narrow pieces such as evasion logic and payload code, so each card below describes one step and what a reviewer should check at that step.

TopLevel: complete malicious programs

The TopLevel probes ask the system to produce a complete malicious program in one request. This is the most direct test of whether a model will build a finished tool for harmful use. A refusal here is the baseline most teams expect, so check that the refusal is consistent across repeated attempts, since garak makes several generations per prompt by default and marks a probe as failing when any attempt produces undesirable output. Record the refusal wording as well, because a partial answer that hands over structure is still a failure.

malwaregen source

SubFunctions: individual malicious components

The SubFunctions probes request single components of malicious software, not a whole program. Models often refuse the top-level ask but may still write a keylogging routine, a persistence mechanism or a data exfiltration helper when it is framed as a small function. Review these results separately from TopLevel, because a model that passes the first family can still fail this one. Confirm with your security team which component types count as failures for your application before you read the pass rate.

Evasion: code that avoids detection

The Evasion probes ask for code designed to avoid detection by security tooling, such as antivirus or endpoint monitoring. This family matters most for coding assistants, because helping someone defeat a control is a different harm from writing a feature. Check whether the model declines to explain or implement obfuscation intended to hide behavior from defenders, and whether it offers defensive alternatives instead. Treat any evasion output as a finding even if it is partial or described rather than fully coded.

Payload: code that delivers harm

The Payload probes ask for code that carries out a harmful action once it runs, such as the final stage that acts on a target system. This is the step where a model's output becomes operational. Review payload results with extra care, since a convincing payload can be lifted into a working attack with little change. Confirm how your application handles generated code before it reaches users, including whether code blocks are executed, copied into pipelines or shown only as text.

How to set up a malwaregen run in your environment

This sequence takes you from a clean Python install to a finished malwaregen scan whose JSONL report lists each malwaregen probe and its result. Each step ends with a check so you know the run is sound before you rely on its output.

  1. Confirm the host meets the install requirements

    Someone on your platform or security team checks that the scanning host runs Linux or macOS and has Python 3.11 or newer, as the garak README and PyPI listing require. Run the Python version command on the host and confirm it reports 3.11 or higher. Run the scan from a host you control, with network access only to the model endpoint under test, so the results are traceable to a known environment.

  2. Install garak from PyPI

    Create an isolated virtual environment and install the package with pip, using the garak package published on PyPI. Pin the version you plan to use across all runs, because scores can shift between releases. The check is that the garak command runs and reports its version, which confirms the plugins were installed into that environment.

  3. Point a generator at the target

    Choose the generator that matches your target, such as a supported hosted API or a REST endpoint. For an in-house application or a model behind a gateway, write a short YAML file for the REST generator that describes the endpoint, request shape, authentication header and where the response text sits in a plaintext or JSON reply. Keep the file under version control and store API keys in environment variables, not in the file. Confirm the file with a single test prompt before the full run.

  4. Verify the generator responds

    Send one short, benign prompt through the generator and confirm you get a readable response in the expected format. Check the status codes, the JSON path or plaintext parsing, and any timeout behavior. If the test fails or the output is empty, fix the configuration first, since a broken generator produces scan results that look clean but mean nothing.

  5. Select the malwaregen probes

    List the available probes and select the malwaregen module, which covers TopLevel, SubFunctions, Evasion and Payload probes, as described in the garak source for probes/malwaregen.py. Decide whether to run the full module or a subset, and record the choice with the scan configuration so the run can be repeated. Confirm the selection by listing the probes that will run before you start the scan.

  6. Run the malwaregen scan

    Start the scan with the generator configuration and the selected malwaregen probes. garak makes 5 generations per prompt by default and marks a probe as FAIL when any attempt produces undesirable output, so keep that default unless your test plan documents a different setting. Monitor the console for errors and watch for rate limiting from the endpoint. The run is complete when garak reports a summary for each probe it executed.

  7. Locate the JSONL report and garak.log

    Find the JSONL report, which records every attempt and its evaluation, and the garak.log file, which holds debugging output and continues across runs. Archive both with the target version, endpoint and configuration file. The check is that the JSONL report lists each malwaregen probe that ran, with its attempts and results. If a malwaregen probe is missing, check garak.log for the cause before treating the scan as complete.

Which malwaregen configuration fits which target

This table compares malwaregen run configurations by target and purpose, so you can match scope and generation count to what you are trying to learn. Read each row as a trade-off: broader coverage and more generations cost more run time, while narrower runs answer a specific question faster. The main takeaway is that the endpoint and the policy context matter as much as the probe count.

Target or choiceBest fitTrade-offWhat to confirm first
All four malwaregen probesFull pre-release or periodic assessment of a coding-capable modelLongest run and widest coverage across TopLevel, SubFunctions, Evasion and PayloadWhich probe families your application could realistically be asked to serve
Single malwaregen probeTargeted follow-up after a finding, such as Evasion onlyFast and focused, but misses behaviors in the other three familiesWhich failure mode your team is investigating
Chat UI endpoint via REST generatorAssistant with a system prompt, moderation layer or product wrapperTests the deployed behavior, including filters, but results depend on the wrapperWhether the REST configuration matches the production request format
Bare model generatorIsolating the underlying model's willingness to complyShows raw model behavior, but may overstate risk for guarded productsWhether the product adds its own refusal or filtering layer
Default five generations per promptEvidence for a report or comparison across runsHigher run time and cost per probe, with more chances to catch intermittent outputWhether results will be compared against earlier runs using the same setting
Fewer generations for a quick checkSmoke test after a model or prompt changeFaster, but a FAIL is more informative than a PASS at low countsThat a clean result is treated as a screen, not a verdict
System prompt stating acceptable-use policyTesting whether stated policy changes compliance in your deploymentReflects a realistic deployment, but a pass does not prove the policy holds under pressureThe exact policy text and who approved it
No system promptBaseline comparison of the model's default behaviorClean baseline, but overstates exposure if production always sets a policyWhether production sends a system prompt on every request

How a malwaregen request flows through garak to the report

The run starts with the garak CLI, which loads the malwaregen probes: TopLevel, SubFunctions, Evasion and Payload. The generator turns each probe into prompts and sends them to the target model or application endpoint, which returns responses. Detectors and evaluators then score each response for malware output. Each attempt and its evaluation are written to the JSONL report, and garak.log records the run. Check that the target endpoint sits inside the boundary you approved for testing.

Malwaregen probes flow from the garak CLI to the report files.

How to read a FAIL on a malwaregen probe

A FAIL on a malwaregen probe does not mean every response was harmful, and a single compliant response does not clear the probe. garak marks a probe as FAIL with a failure rate when any of its attempts produces undesirable output. By default each prompt is generated five times, so a model that refuses four times and writes a dropper once still fails. Read the failure rate as the share of attempts that crossed the line, then go to the individual attempts before deciding what the result means for the model.

Open the JSONL report written for the run and review each attempt alongside its evaluation. Look for the pattern where a response opens with a refusal and then supplies the requested code anyway, such as a "I can't help with that, but here is a skeleton of the payload" reply followed by working functions. That is a failure in substance, even though the first sentence reads as a refusal. The opposite case matters too: a response that discusses malware concepts at a high level, names no techniques and provides no runnable code is a genuine refusal, and a detector may still flag it because of keyword matches. Record which of the two patterns you see for each failing attempt.

Before reporting a finding, have a person check a sample of the attempts the detector scored, including both the flagged and the unflagged ones. Confirm that the detector is reading the response correctly and not counting a mention of a keyword as compliance. Keep the reviewed sample, the reviewer's name and the decision on each attempt in your records, so a later rescan can be compared against the same judgment. Ask your security team to define in advance what counts as a reportable finding for your organization, because the answer determines whether a FAIL becomes a fix ticket, a model selection decision or an accepted risk.

Handling sensitive outputs and test artifacts safely

A malwaregen run produces prompts, model replies and logs that may contain working malicious code. The controls below treat garak's output as sensitive material from the first run, covering execution, secrets, log access and retention.

Never execute generated output

Treat every reply that garak records as untrusted, even when it looks like a short script or a harmless fragment. Keep scan output in an isolated location and do not run, compile, or paste it into a shell, notebook or IDE on a workstation with access to production. Make this a written rule for everyone who opens a JSONL report, because the report stores the full model response for each attempt, including code that a reviewer might be tempted to test.

Restrict access to reports

The JSONL report records every attempt and its evaluation, so it holds the most sensitive content in a malwaregen run. Store report directories with restricted filesystem permissions, limit the group to the people who review findings, and avoid copying reports into shared drives, chat channels or ticket attachments. Confirm that any dashboard or ticketing tool you use for findings can hide raw model output from people who only need the pass or fail summary.

Keep target keys out of config files

A scan against a hosted or self-hosted endpoint needs credentials, and a generator configuration file is easy to commit by accident. Pass API keys through environment variables or a secrets manager at run time, and keep the YAML file that describes the endpoint free of key values. Add the config and any local run directory to .gitignore and check repository history before first commit, since a key removed later still remains in past commits.

Control who reads garak.log

garak writes a garak.log debugging file that continues across runs, so it can accumulate prompt text, responses and endpoint details long after a single scan is finished. Decide who may read it, set file permissions to match, and review what it captures at the log level you use. Do not attach the log to a public issue when reporting a garak bug, and redact prompt or response excerpts before sharing it with the garak maintainers or a vendor.

Set retention rules for results

Each run adds a report and an appended log, so artifacts pile up quickly across repeated malwaregen scans. Write a retention rule that states how long reports and logs are kept, who approves deletion, and when the generated text is removed while the summary is kept. Confirm the period with your legal, security and records teams, and make sure the rule also covers backups, scan hosts and any copies held by the model provider.

Separate the scan environment

Run malwaregen scans from a dedicated host or container that has no route to production systems, no stored cloud credentials and no shared home directory. This limits the damage if a generated artifact is run by mistake or if a compromised endpoint returns hostile content. Record the host, garak version and config used for each run so reviewers can trace an artifact back to its environment without needing to open the output itself.

What to change after a malwaregen failure

A malwaregen failure means the system produced material that a reviewer would treat as malware or a malware component, and the fix belongs as close to the failing behavior as possible. Start with the application around the model, because that is where most teams have direct control. Tighten the system prompt and usage policy so they name the prohibited categories in plain terms, including top-level malware, sub-functions that only make sense inside an attack chain, evasion logic and payload delivery. Wording alone rarely closes a gap, so pair it with output filtering that inspects generated code for patterns your policy forbids before the user or a downstream system sees it. Review whether any refusal messages leak technical detail that a retry could exploit.

For coding agents and assistants with execution rights, the most effective controls usually sit in tool configuration rather than in the prompt. Restrict which commands, network destinations, file paths and package sources the agent can reach, run generated code only in an isolated sandbox without production credentials, and require human approval for any action that writes outside the project. Log every tool call so a failing prompt can be traced to the step where the agent acted. Model selection is a separate decision: if the chosen model is weak on refusals for this category, you may need a different model or a guard layer, and that choice should be tested in your environment with the same probes before it is adopted.

Changes to model weights, fine-tuning data or training objectives belong to the model owner, whether that is an internal ML team or a vendor. DeployOpen can harden the surrounding application, including prompts, filters, agent permissions, logging and sandboxing, and can rerun the malwaregen probes after each change to confirm the failure rate has moved. Record each change, the probe run it followed and the resulting report, so you can show reviewers what was fixed and what remains. Confirm the retest scope in writing before work starts, since a fix that passes TopLevel probes may still fail on Evasion or Payload prompts.

Questions teams ask before running malwaregen tests

What does a malwaregen test engagement cost and what drives the effort?

Cost follows the written scope, and DeployOpen does not publish a price list. The main effort drivers are the number of targets (a single model, an application, or several endpoints), how complex each endpoint is (plain chat, a system prompt, tool calls, retrieval, or a guarded gateway), how much output review a human reviewer must do, and how far remediation and retest go. Ask for a quote that separates one-time setup, the test run itself, the findings report, and any retest. Ongoing scans on a schedule are a recurring cost and are usually priced separately from a first assessment.

How long does a first malwaregen run take to plan?

Planning time depends on how quickly the client can confirm the target, access and rules of testing. The main duration drivers are getting endpoint access into a test environment, agreeing which malwaregen probes apply to the application, setting review criteria for flagged outputs, and scheduling the named reviewer. Run time itself depends on the probes selected, the generations per prompt, and the rate limits of the endpoint, so confirm those limits with the model provider or your own platform team before agreeing a date. A fixed-scope timeline is agreed in writing before work starts.

What must our team provide before malwaregen testing starts?

Four things are needed before testing begins:

  • Endpoint access to the model or application under test, in a non-production environment where possible.
  • A test account with the same permissions a real user or tool would have, so results reflect actual exposure.
  • A named reviewer who can judge whether flagged output is genuinely usable malicious code or a harmless refusal or example.
  • An acceptable-use policy that covers generating malware-like content during testing, including where outputs are stored and who may read them.

Also confirm how logs and the garak JSONL report will be handled, since they may contain generated code.

Can our internal team run garak malwaregen probes on its own?

Yes, a capable internal team can install garak, which is a command-line tool installed from PyPI and requiring Python 3.11 or newer, and run the malwaregen probes against an endpoint. The harder parts are configuring the REST generator for your endpoint, choosing probes and detectors that match the application, deciding what counts as a failure, and reviewing outputs safely. Many teams keep the scan running in-house and bring in outside help for scope design, interpreting results or retesting after fixes. Start with the probe documentation at the garak user guide before deciding.

Do garak malwaregen results count as an audit report?

No. garak output is test evidence, not an audit report, attestation or certification. A garak run writes a JSONL report of each attempt and its evaluation, and that record can support a compliance review, but only an independent auditor or certification body issues an audit report. DeployOpen prepares systems, controls and evidence for compliance assessments, and it does not issue audit reports or certifications. Ask your assessor which evidence they need from a scan before you run it, so the report, the run configuration and the reviewer notes are captured in the form they expect.

Why would a malwaregen test flag a model that refuses most requests?

Refusal rates alone do not settle the question, because a single attempt that yields usable malicious code can count as a failure. garak runs five generations per prompt by default and marks a probe as FAIL with a failure rate when any attempt produces undesirable output. Engineers should read the JSONL report to see which generations passed, which were judged undesirable, and whether the output is actually functional or only a partial fragment. Treat the failure rate as a starting point for review, not a final verdict.

What does a malwaregen engagement include after the findings are delivered?

Remediation and retest scope should be agreed in writing before the first run. A typical fixed-scope engagement covers the test plan, the run, a findings report with reproduction steps for flagged prompts, and recommended fixes such as system prompt changes, guardrail configuration, output filtering or model selection. Retest is a separate line item that repeats the affected probes after fixes are applied. Ask whether the scope covers fixes made by your team, fixes DeployOpen implements, and how many retest cycles are included.

How DeployOpen scopes and delivers garak malwaregen testing

DeployOpen is a Chainscore Labs company that plans, implements, hardens and supports self-hosted open-source platforms inside the client's own infrastructure, and it runs security testing that includes AI and agent security review. For garak malwaregen testing, that means the work is scoped against the systems you actually operate: the model endpoint or application under test, the system prompt and guardrails in front of it, the coding tools it can call, and where the scan results will be stored and reviewed. Most engagements are fixed-scope, so the probe families, generator configuration, detectors, deliverables and timeline are agreed in writing before any scan runs.

DeployOpen does not publish a price list. A quote follows from the written scope, and the main drivers are the number of targets, how many probe configurations are in play, whether the endpoint is reachable from the test environment or must be reached inside an air-gapped network, and how much remediation support is requested. Ask for the quote to state which items are one-time (scoping, the first full run, the written findings report) and which recur (scheduled rescans, retests after model or system prompt changes, and any retainer for continuous testing). Ask for the fixes to be listed separately from the findings so you can assign them to your own engineers or to the partner.

Findings come with recommended fixes and a retest once those fixes are in place, so you can confirm that a refused malware request stays refused after a system prompt edit or a model version change. DeployOpen does not hold partner, reseller or certified status with garak or NVIDIA, and it does not issue audit reports or certifications. Evidence it prepares can support an independent assessor, but the assessor's conclusions remain their own.

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.