Command-line tools

SPARTA provides two command-line tools, built on the standalone libraries (see SPARTA Standalone libraries):

sparta-cli

A tool for the threat elicitation and risk analysis of a SPARTA model from the command line, with exports of the threats to CSV, XLSX, text files, a statistics report or a code-quality report, or a submission to a server that is not part of SPARTA.

sparta-ci

A tool for continuous integration pipelines, configured with a .sparta.yml file, that analyzes a model and submits the threats and the model to a server that is not part of SPARTA.

Both tools use the threat elicitation and risk analysis engine of sparta-core, with the threat type catalogs that the model references.

Obtaining the tools

Each tool is a single runnable jar that contains all its dependencies (EMF, VIATRA, …):

Tool

Maven coordinates

Runnable jar

Main class

sparta-cli

be.kuleuven.cs.distrinet.sparta:sparta-cli:2026.2.0, classifier shaded

sparta-cli-2026.2.0-shaded.jar (about 70 MB)

be.kuleuven.cs.distrinet.sparta.cli.SpartaCli

sparta-ci

be.kuleuven.cs.distrinet.sparta:sparta-ci:2026.2.0, classifier shaded

sparta-ci-2026.2.0-shaded.jar (about 73 MB)

be.kuleuven.cs.distrinet.sparta.cli.ci.SpartaCi

The jars without classifier (sparta-cli-2026.2.0.jar and sparta-ci-2026.2.0.jar) are library jars and cannot be run with java -jar.

Download the runnable jars from the GitHub release page, or from the SPARTA Maven repository with the Maven coordinates above, for example https://maven.sparta.distrinet-research.be/be/kuleuven/cs/distrinet/sparta/sparta-cli/2026.2.0/sparta-cli-2026.2.0-shaded.jar. Put them in a folder without spaces in its path (see Known limitations in 2026.2).

You can also build the jars from source. Building the whole repository with mvn clean package from the repository root (see Building SPARTA from source) produces them in the target folders of the standalone modules:

  • standalone/sparta-cli/target/sparta-cli-2026.2.0-shaded.jar

  • standalone/sparta-ci/target/sparta-ci-2026.2.0-shaded.jar

The tools need Java 21 or later. Run them with java -jar, for example:

java -jar sparta-cli-2026.2.0-shaded.jar -i MyModel.sparta --outcsv threats.csv

Changed in version 2026.2: The runnable jars are also available from the SPARTA Maven repository, and the tools require Java 21; earlier releases ran on Java 11.

sparta-cli

Usage

sparta-cli loads one model, runs threat elicitation and risk analysis, and passes the resulting threats to every exporter whose option you give, so a single run can produce several outputs. -h prints the following help (the jar name in the usage line is always sparta-cli.jar):

usage: java -jar sparta-cli.jar [--about] [--codequalityreport <arg>]
       [--commitid <arg>] [-h] [-i <arg>] [--outcsv <arg>]
       [--outstatistics <arg>] [--outtxt <arg>] [--outxlsx <arg>]
       [--server <arg>] [--token <arg>] [-v] [--version]
    --about                     About SPARTA
    --codequalityreport <arg>   Export Code Quality Report
    --commitid <arg>            Server submission commit id
 -h,--help                      Show help
 -i,--input <arg>               Model to analyze
    --outcsv <arg>              CSV Export file
    --outstatistics <arg>       Output txt file with threat statistics
    --outtxt <arg>              TXT export files
    --outxlsx <arg>             XLSX export file
    --server <arg>              Server submission url
    --token <arg>               Server submission token
 -v,--verbose                   Provide verbose output
    --version                   Show version info

A run proceeds as follows:

  1. The arguments are parsed. An unknown option or a missing option argument prints an error and the help, and ends the run with exit status 1.

  2. --about, --help and --version are handled, in that order. If -h is given, the run ends after the help: -h -i MyModel.sparta prints the help and does not analyze the model.

  3. If -i is given, the model is loaded and analyzed, and the exporters run in this order: CSV, XLSX, text files, statistics, code-quality report, server submission. An exporter that fails logs an error, and the next exporters still run; at the end, the run logs One or more exports failed. and exits with status 1. Without -i, nothing is analyzed or exported.

Options

No option is required and no option has a default value. Only -h, -i and -v have a short form; use the long form of all other options, for example --outcsv threats.csv.

Short

Long

Argument

Description

-i

--input

file

Model to analyze: a .sparta file (or a .securitydfd or .spartamodel file), relative to the working directory or absolute. See Input model.

--outcsv

file

Write the threats to a CSV file.

--outxlsx

file

Write the threats to an Excel (XLSX) file.

--outtxt

directory

Write one text file per threat into this directory.

--outstatistics

file

Write a plain-text statistics report.

--codequalityreport

file

Write a code-quality report (JSON).

--server

URL

Submit the threats to this https URL. Requires --token and --commitid.

--token

token

Value of the token header of the submission.

--commitid

commit id

Value of the commitId header of the submission.

-h

--help

Print the help to standard output, without analyzing a model.

--version

Log the version, for example Version: 2026.2.0.

--about

Log a short description of the tool.

-v

--verbose

No effect in 2026.2. See Logging for more detailed output.

Migrating scripts from 2026.1

Changed in version 2026.2: The short forms of the options with more than one letter, and the option -it (--inputtree), which had no effect, were removed. The long forms did not change.

Replace the removed options of a 2026.1 script as follows:

2026.1

2026.2

-oc, -ox, -ot, -os

--outcsv, --outxlsx, --outtxt, --outstatistics

-cqr

--codequalityreport

-su, -st, -sc

--server, --token, --commitid

-ab, -ve

--about, --version

-it, --inputtree

leave it out

-h, -i, -v and the long forms

unchanged

For example, -i MyModel.sparta -oc threats.csv becomes -i MyModel.sparta --outcsv threats.csv. Most of the old short options now end the run with Unrecognized option and exit status 1, and -ve with Ambiguous option. Do not rely on the old forms that are still accepted because they abbreviate a long option, such as -ab for --about.

Also check the other changes of 2026.2 that can affect scripts: the exit status (see Exit status), the https requirement of the server submission (see Server submission), the number format of the CSV file (see Exports), and Java 21 (see Obtaining the tools).

Input model

  • The -i path is resolved against the working directory, unless it is absolute.

  • Files with the extensions .sparta, .securitydfd (the legacy name) and .spartamodel are loaded as SPARTA models. A file with another extension is read as a generic XMI file, which works if it contains a SPARTA model.

  • After loading the model, sparta-cli loads every resource the model references, such as the threat type catalogs and solution catalogs that are linked to it (see Pairing existing threat type catalogs). Relative references are resolved against the location of the model file, so the catalog files must be at the same relative location as in your workspace. Catalog files that the model does not reference are not loaded, and there is no option to add catalogs or pattern files.

  • If a referenced catalog cannot be loaded, for example because the file is missing or the reference is an Eclipse workspace URI (platform:/resource/...), the run still succeeds, without a warning, but finds no threats from that catalog (no threats at all if no catalog could be loaded).

  • Risk is calculated with a Monte Carlo simulation of 1000 samples and no fixed seed, so risk values differ slightly between runs. The order of the threats is not stable either.

Exports

After the analysis, sparta-cli passes the threats to every exporter whose option you give; you can combine several. The first five exporters below write the threats to files; the server submission sends them to a server instead.

For the files:

  • Output paths are relative to the working directory, unless they are absolute.

  • Missing parent directories of output files are not created: the exporter logs an error, and the run exits with status 1 after the other exporters.

  • Existing files are overwritten.

  • Text files (CSV, text files, statistics and code-quality report) are written in UTF-8.

Changed in version 2026.2: Text files are always written in UTF-8; before, they used the default character encoding of the JVM.

CSV (--outcsv)

One header line followed by one line per threat. Fields are separated by ; and every field is enclosed in double quotes; a double quote inside a value is written twice. The format is the same as the CSV export of the ThreatAnalysis view; Analysis results and exports describes the columns.

For legacy key-based threat types (see Writing threat type patterns), Type and Name are both the name of the threat type. For threats of patterns without a data flow, Flow From, Data Flow and Flow To are empty.

Numbers have at most 4 decimals, a decimal point and a comma as grouping separator, whatever the locale of the JVM, for example 7,700.1363.

Changed in version 2026.2: Double quotes inside values are escaped, and numbers no longer follow the default locale of the JVM.

"Type";"Name";"Location";"Flow From";"Data Flow";"Flow To";"Vulnerability";"Risk";"Risk (lower)";"Risk (upper)";"Risk (potential)"
"Repudiation";"Contoso repudiates action";"Contoso";"Contoso";"Write";"Database";"1";"7,700.1363";"78.9585";"45,704.8636";"7,700.1363"

XLSX (--outxlsx)

One sheet with the same columns as the CSV file, with the numbers as numeric cells. For threats of patterns without a data flow, the cells Flow From, Data Flow and Flow To contain the text null.

Text files (--outtxt)

Creates the directory, including missing parent directories, and writes one file per threat, with one line for each CSV column: the column name, a colon, a tab character, and the value:

Type:        Tampering
Name:        Database corrupted
Location:    Database
Flow From:   Contoso
Data Flow:   Write
Flow To:     Database
Vulnerability:       1
Risk:        23,763.1892
Risk (lower):        959.8419
Risk (upper):        118,439.7156
Risk (potential):    23,763.1892

The file name joins the raw threat type name, the threatened element name and the data flow name with _, replaces every run of other characters than ASCII letters, digits and _ with one space, and appends .txt. For example, the threat type <$location$> corrupted on element Database and flow Write gives a file named location corrupted_Database_Write.txt preceded by a space. Threats with the same threat type, element and flow overwrite each other’s file. For threats without a data flow, this export fails (see Known limitations in 2026.2).

Statistics (--outstatistics)

Writes a plain-text report with statistics over all threats, computed with ThreatAggregationAnalysis (see Aggregated risk analyses):

  • the number of threats, threat types and element types;

  • the total risk reduction by the countermeasures;

  • the average number of threats per threatened element;

  • the risk reduction per threat type and per element type;

  • the number of threats per threat type and per element type, with their share of all threats.

For example:

SPARTA Threat Statistics Report
===============================

55 threats encountered (9 threat types, 3 element types)

Risk reduction:      13.33% (389262.23/449107.86)

Average threat count:        9.17

Threat Type Reduction Progress
------------------------------
<$location$> spoofed
             42.82% (42323.46/74013.39)
...
Element Type Reduction Progress
-------------------------------
Process
             14.47% (277608.07/324559.27)
...

Threat Type Threat Counts
-------------------------
<$location$> spoofed
             10      (18.18%)
...
Element Type Threat Counts
--------------------------
Process
             44      (80.00%)
...
  • The totals are sums of the expected risk values of the threats. The numbers in parentheses are residual risk / potential risk; the percentage is the reduction, 1 - residual / potential.

  • “Average threat count” is the average number of threats per threatened element.

  • Threat types are listed with their raw names (placeholders are not replaced), and element types by class name (Process, DataFlow, DataStore, ExternalEntity, …).

  • The order of the entries within a section is unspecified.

  • Unlike the other exports, the statistics report formats numbers with the default locale of the JVM, for example 13,18% instead of 13.18% with a Belgian locale. To choose the locale, set -Duser.language and -Duser.country, for example java -Duser.language=en -Duser.country=US -jar ....

Code-quality report (--codequalityreport)

Writes a report in the format of GitLab Code Quality reports, so that a CI system can show the threats as code-quality findings on the model file. The report is a single-line JSON array with one entry per threat, which identifies the threat, gives it a severity based on its risk, and points to the model file.

For example:

[{"description":" location disrupted_Database_Write.txt","fingerprint":"795a653ba8f51ca08131f1d80afd2232","severity":"blocking","location":{"path":"Contoso.sparta","lines":{"begin":1}}}]
description

The text file name of the threat (see Text files (–outtxt)). For threats without a data flow, the export fails (see Known limitations in 2026.2).

fingerprint

The MD5 hash of description. Threats with the same threat type, element and flow therefore share a fingerprint.

severity

The risk of the threat relative to the highest potential risk among all threats (r = risk / maximum potential risk): info (r < 0.125), minor (r < 0.375), major (r < 0.625), critical (r < 0.875) or blocking. GitLab expects blocker for the highest severity: it shows threats with blocking with the severity “Unknown”, at the bottom of the list (see Using the tools in a CI pipeline for a workaround).

location

path is the path of the model file relative to the working directory, and lines.begin is always 1. For a model in a subdirectory, the path contains a double slash, for example models//MyModel.sparta. For a model outside the working directory, path is the full path of the model without the leading /. On Windows, path is always the full path of the model without the drive letter, for example Users/me/models//MyModel.sparta.

Server submission (--server, --token, --commitid)

Note

The server is not part of SPARTA: to use the submission, you need a server of your own that accepts the request described below.

Sends the threats as JSON to a server, together with a token and a commit id. --server gives the URL of the server, --token the token and --commitid the commit id. sparta-cli only sends the threats if all three options are given; if one of them is missing, it sends nothing and does not report this.

The URL must use https, so that the token is not sent in the clear: any other protocol is refused with the error Refusing to submit to SPARTA server over insecure protocol '<protocol>'; .... sparta-cli sends POST <url> with the headers Content-Type: application/json; utf-8, token: <token> and commitId: <commit id>, and a body in UTF-8. The connection times out after 30 seconds, and reading the response after 60 seconds. The body is a JSON array with one object per threat, with these properties: threatTypeName, threatName, description, vulnerability, risk, potentialRisk, threatenedElementName, threatenedElementTypeName, threatenedElementId, dataFlowName, dataFlowFromName and dataFlowToName.

For example, one object of the array:

{"dataFlowName":"Write","dataFlowToName":"Database","dataFlowFromName":"Contoso","risk":7803.1698230017455,
 "description":"Contoso claims not to have written to Database.","vulnerability":1.0,"threatName":"Contoso repudiates action",
 "threatTypeName":"Repudiation","potentialRisk":7803.1698230017455,"threatenedElementTypeName":"Process",
 "threatenedElementId":"_S4cWwMk6EeeheeqXVGLgxA","threatenedElementName":"Contoso"}

threatenedElementId is the ID of the threatened element in the model file (its xmi:id), so it is the same in every run. If the server answers with an HTTP status below 400, sparta-cli logs the response body and SPARTA Server submission successful (HTTP <status>). An HTTP status of 400 or higher is logged as SPARTA Server submission failed (HTTP <status>): <response body>, and connection errors and timeouts are logged as errors as well. In all these error cases, and for a URL that is not https, the submission counts as a failed export, so the run exits with status 1.

Changed in version 2026.2: The submission requires https, has timeouts, writes the body in UTF-8, treats HTTP errors as failures, and makes the run exit with status 1 when it fails. threatenedElementId is the xmi:id of the element instead of an identifier that changed between runs.

Logging

sparta-cli logs to standard error at level INFO, in the form [main] INFO <logger> - <message>; the help goes to standard output. The --version and --about texts are logged, so they also appear on standard error. For more detail, set the log level with a system property:

java -Dorg.slf4j.simpleLogger.defaultLogLevel=debug -jar sparta-cli-2026.2.0-shaded.jar -i MyModel.sparta

At level debug, the log shows the working directory, the name of the loaded model and one Threat: ... line per threat; at level trace it also lists the threat types and threat specifications that were loaded. Errors of exporters are logged with their stack trace.

Exit status

sparta-cli exits with status 0 when the run succeeds, and with status 1 when it fails.

Situation

Exit status

Successful run, run without options, -h, --version or --about

0

Referenced catalogs not found (no threats)

0

Unknown option (including the removed short options such as -oc) or missing option argument

1

An exporter failed, for example because of a missing output directory, a server URL that is not https, an HTTP error or a timeout; logged as One or more exports failed.

1

Model not found or cannot be loaded

1 (uncaught exception)

--outtxt or --codequalityreport with threats without a data flow, or a threat without a data flow to which a countermeasure with a scope applies (see Known limitations in 2026.2)

1 (uncaught exception)

There is no option to fail on a risk threshold.

Changed in version 2026.2: A failed export or server submission makes the run exit with status 1; before, the exit status stayed 0.

Examples

Analyze Contoso.sparta in the working directory and write a CSV file, an XLSX file, text files, a statistics report and a code-quality report:

java -jar sparta-cli-2026.2.0-shaded.jar -i Contoso.sparta --outcsv threats.csv --outxlsx threats.xlsx --outtxt txt --outstatistics stats.txt --codequalityreport cqr.json

The same with --input, writing into an existing directory out:

java -jar sparta-cli-2026.2.0-shaded.jar --input Contoso.sparta --outcsv out/threats.csv --outtxt out/threats --outstatistics out/statistics.txt --codequalityreport out/gl-code-quality-report.json

Submit the threats to a server:

java -jar sparta-cli-2026.2.0-shaded.jar -i Contoso.sparta --server https://server.example.org/api/submit --token <token> --commitid <commit id>

A typical run logs:

[main] INFO be.kuleuven.cs.distrinet.sparta.cli.SpartaCliProcessor - LS: false
[main] INFO be.kuleuven.cs.distrinet.sparta.cli.SpartaCliProcessor - Rete: true
[main] INFO be.kuleuven.cs.distrinet.sparta.cli.SpartaCliProcessor - Running SPARTA Analysis ...
[main] INFO be.kuleuven.cs.distrinet.sparta.cli.cmd.export.ExportCSV - Exporting to csv
[main] INFO be.kuleuven.cs.distrinet.sparta.cli.cmd.export.ExportXLSX - Exporting to xlsx files
[main] INFO be.kuleuven.cs.distrinet.sparta.cli.cmd.export.ExportTXT - Exporting to txt files
[main] INFO be.kuleuven.cs.distrinet.sparta.cli.cmd.export.ExportStatistics - Exporting threat statistics
[main] INFO be.kuleuven.cs.distrinet.sparta.cli.cmd.export.ExportCQR - Exporting to cqr

sparta-ci

Note

The server that sparta-ci submits to is not part of SPARTA: you need a server of your own that accepts the request described below and in Server submission (–server, –token, –commitid).

sparta-ci analyzes the model configured in .sparta.yml and submits the threats, together with the model, to a server. It writes no local output files and ignores all command-line arguments (including --help). Run it in the directory that contains .sparta.yml:

java -jar sparta-ci-2026.2.0-shaded.jar

A run proceeds as follows:

  1. sparta-ci reads .sparta.yml from the working directory.

  2. It looks for a git repository, starting from the directory of .sparta.yml and searching upward (the GIT_DIR environment variable is honored). If it finds one, the commit id of HEAD becomes the commit id of the submission; a detached HEAD, as in many CI checkouts, works as well.

  3. It analyzes the model exactly like sparta-cli, so the same Input model rules apply.

  4. It builds a self-contained copy of the model: the catalogs and other SPARTA resources that the model references are copied into the model, and the legacy key-based patterns and types maps of threat types and threat specifications are cleared. The VQL patterns of the catalogs are kept. This copy is serialized as XMI (UTF-8).

  5. It submits the results in the same way as sparta-cli (see Server submission (–server, –token, –commitid)): POST <server.url> over https, with the headers Content-Type: application/json; utf-8, token: <server.token> and commitId: <commit id>, a UTF-8 body, and the same timeouts and messages.

Because the URL is only checked when the results are submitted, a server.url that is not https is reported after the whole analysis.

Changed in version 2026.2: The submission requires https, has timeouts and treats HTTP errors as failures, and sparta-ci exits with status 1 when it fails (see Exit status).

Configuration file

.sparta.yml has the following keys. Unknown keys are ignored.

Key

Required

Meaning

input.model

yes

Path of the model, relative to the working directory or absolute (.sparta, .securitydfd or .spartamodel).

server.url

yes

https URL to submit the results to.

server.token

no

Value of the token header. The value is used literally; there is no environment variable substitution.

overrideCommit

no

Commit id to send when no git repository is found. Inside a git repository, the HEAD commit is always used instead. Without a git repository and without overrideCommit, the commitId header is empty.

version

no

An integer. Read but not used in 2026.2.

For example:

version: 1
input:
  model: Contoso.sparta
server:
  url: https://server.example.org/api/submit
  token: <submission token>
overrideCommit: deadbeef    # only used outside a git repository

Warning

Because the token is read literally from the file, do not commit a real token to your repository.

Payload

The request body is a JSON object with two properties:

threatList

The threats, with the same properties as the sparta-cli server submission (see Server submission (–server, –token, –commitid)).

model

The self-contained model as an XMI string.

{"threatList":[{"dataFlowName":"Write", ... }, ...],"model":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<spartamodel:DFDModel ...>"}

Exit status

sparta-ci exits with status 0 only when the server accepted the submission, so a failed run fails a pipeline job.

Situation

Result

Exit status

Successful run

Results submitted, server answered with an HTTP status below 400

0

No .sparta.yml in the working directory

Logs Did not find SPARTA ci configuration.

1

Submission failed: server.url missing or not https, server unreachable, timeout, or HTTP status 400 or higher

Logs the error after the analysis

1

input.model missing

NullPointerException

1

Model not found

Uncaught exception

1

Changed in version 2026.2: sparta-ci exits with status 1 when the configuration file is missing or the submission fails; before, it exited with status 0.

Using the tools in a CI pipeline

The SPARTA 2026.2 repository contains no ready-made pipeline configuration. You can run the tools in any CI system that can run Java. For example, the following GitLab CI job runs sparta-cli on a model. It assumes that the shaded jar and the model, with its catalogs at the referenced relative paths, are available in the job’s working directory:

threat-model:
  image: eclipse-temurin:21-jre
  script:
    - java -jar sparta-cli-2026.2.0-shaded.jar -i model/MySystem.sparta --outcsv threats.csv --outstatistics threat-statistics.txt --codequalityreport gl-code-quality-report.json
    - sed -i 's/"severity":"blocking"/"severity":"blocker"/g' gl-code-quality-report.json
  artifacts:
    paths: [threats.csv, threat-statistics.txt]
    reports:
      codequality: gl-code-quality-report.json

sparta-cli exits with status 1 when an export fails, so the job fails without extra checks. It does not fail when the analysis finds no threats (for example when catalogs are missing): the CSV then contains only the header line.

The sed step replaces the severity blocking, which GitLab does not know, by blocker, so that GitLab shows the threats with the highest risk as “Blocker” instead of “Unknown”.

To use sparta-ci instead, commit a .sparta.yml in the directory the job runs from and run java -jar sparta-ci-2026.2.0-shaded.jar. The commit id is then taken from the checked-out commit. Keep in mind that sparta-ci reads the token from the file; with sparta-cli, you can pass the token on the command line (--token) from a protected CI variable, but sparta-cli does not send the model.

Known limitations in 2026.2

Threats without a data flow break the text and code-quality exports

For a threat of a catalog pattern that binds no flow or df parameter, for example from a STRIDE-per-element catalog, --outtxt and --codequalityreport fail with a NullPointerException and the run ends with exit status 1; the exporters that come after them do not run. The CSV, XLSX and statistics exports work for these threats.

Threats without a data flow and countermeasures with a scope

If a countermeasure with a non-empty scope applies to a threat without a data flow, the risk calculation fails with a NullPointerException before any exporter runs (see The role of the data flow).

Severity “Unknown” in GitLab

The code-quality report uses the severity blocking for the threats with the highest risk, but GitLab only knows blocker. GitLab still reads the report, but shows these threats with the severity “Unknown”, at the bottom of the list. Replace the severity in the report before GitLab reads it, as in Using the tools in a CI pipeline.

ProvisionException at startup

When the path of the jar contains a space, for example C:\Users\Jane Doe\tools\sparta-cli-2026.2.0-shaded.jar, both tools abort before the analysis with a com.google.inject.ProvisionException and exit status 1. The cause is a NoSuchFileException for the jar itself, with the space written as %20. Put the jar in a folder without spaces in its path.

.txt models in sparta-ci

sparta-ci tries to convert an input.model that ends with txt from a simple YAML description into a model. This does not work in 2026.2: the conversion fails with a NullPointerException, and the converted model would not be found anyway. Use a .sparta model.

Troubleshooting

Unrecognized option: -oc (or another option of two or three letters)

The script still uses an option of 2026.1. See Migrating scripts from 2026.1.

No threats found

The catalogs referenced by the model were not found. Check that the catalog files exist at the relative paths stored in the model, and that the model does not reference them with platform:/resource/... URIs. See Input model.

Risk values differ between runs

The risk calculation uses Monte Carlo sampling without a fixed seed. Small differences between runs on the same model are expected; the order of the threats can also differ.

Unexpected number format in the statistics report

The statistics report uses the default locale of the JVM. Set -Duser.language and -Duser.country to choose a locale.