Skip to main content

Nagini is an automatic verifier for statically typed Python programs, based on the Viper verification infrastructure. Nagini is being developed at the Programming Methodology Group at ETH Zurich.

Our CAV 2018 tool paper describing Nagini can be found here, and a more detailed description of its encoding can be found in Marco Eilers’ thesis. Also see the Wiki for the documentation of Nagini’s specification language. See the changelog for the version history.

Dependencies (Ubuntu Linux)

  1. Install Java 11 or newer (64 bit) and a Python version between Python 3.12 and 3.14 (64 bit).

  2. Install the the required libraries, in particular, python3.x-dev.

  3. For usage with Viper’s verification condition generation backend Carbon, you will also need to install Boogie (version 2.15.9).

Dependencies (Windows)

  1. Install Java 11 or newer (64 bit) and a Python version between Python 3.12 and 3.14 (64 bit).

  2. Install the required version of either Visual C++ Build Tools or Visual Studio.

  3. For usage with Viper’s verification condition generation backend Carbon, you will also need to install Boogie (version 2.15.9).

Getting Started

Execute the following commands (on Windows, you may have to use cmd and not PowerShell):

  1. Create a virtual environment:

    virtualenv --python=python3.14 <env>
  2. Activate it:

    source env/bin/activate

    on Linux, or:

    env\Scripts\activate

    on Windows.

  3. Install Nagini:

    pip install nagini
    # or with optional dependencies for server mode and testing:
    pip install "nagini[server,test]"

    Alternatively, to get the most up-to-date version, install from source:

    git clone https://github.com/marcoeilers/nagini.git
    cd nagini
    pip install .
    # or with optional dependencies for server mode and testing:
    pip install ".[server,test]"
  4. Optionally, try running some tests:

    pytest -v -p no:faulthandler src/nagini_translation/tests.py --silicon --minimal

Command Line Usage

To verify a specific file from the nagini directory, run:

nagini [OPTIONS] path-to-file.py

You may have to explicitly supply a path to a Z3 executable (use version 4.8.7, other versions may offer significantly worse performance) using the command line parameter --z3=path/to/z3. Additionally, you may have to set the environment variable JAVA_HOME to point to your Java installation. See the wiki for information on how to write specifications in Nagini.

The following command line options are available:

--verifier
                Selects the Viper backend to use for verification.
                Possible options are 'silicon' (for Symbolic Execution) and 'carbon'
                (for Verification Condition Generation based on Boogie).
                Default: 'silicon'.

--select
                Select which functions/methods/classes to verify. Expects a comma-
                separated list of names.

--counterexample
                Enable outputting counterexamples for verification errors (experimental).

--sif=v
                Enable verification of secure information flow. v can be 'true' for ordinary
                non-interference (for sequential programs only), 'poss' for possiblistic
                non-intererence (for concurrent programs) or 'prob' for probabilistic non-
                interference (for concurrent programs).

--float-encoding
                Selects a different encoding of floating point values. The default is to model floats
                as abstract values and all float operations as uninterpreted functions, so that essentially
                nothing can be proved about them. Legal values for this option are 'real' to model floats
                as real numbers (i.e., not modeling floating point imprecision), or 'ieee32' to model them
                as proper IEEE 32 bit floats. The latter option unfortunately usually leads to very long
                verification times or non-termination.

--int-bitops-size
                Bitwise operations on integers (e.g. 12 ^ -5) are supported only for integers which can
                be proven to be in a specific range, namely the range of n-bit signed integers.
                This parameter sets the value of n.
                Default: 8.

--boogie
                Sets the path of the Boogie executable. Required if the Carbon backend
                is selected. Alternatively, the 'BOOGIE_EXE' environment variable can be
                set.

--viper-jar-path
                Sets the path to the required Viper binary ('viperserver.jar').
                A single jar bundles both the Silicon and Carbon backends, so it
                is used regardless of the selected backend. You can either use the
                provided binary packages installed by default or compile your own
                from source (see below).
                Expects either a single path or a colon- (Unix) or semicolon-
                (Windows) separated list of paths. Alternatively, the environment
                variable 'VIPERSERVERJAR' can be set, or 'VIPERJAVAPATH' for a
                full explicit classpath.

To see all possible command line options, invoke nagini without arguments.

Server Mode / Faster Verification Mode

Nagini has to do a significant amount of work on startup, and has to start a JVM to run Viper. To avoid some of that startup work and speed up Viper’s runtime, Nagini has a server mode. To use it,

  1. Install pyzmq:

    pip install "nagini[server]"
  2. Start a Nagini server:

    nagini --server <otherArgs> dummyFile.py

    Note that all required arguments, including JAVA_HOME and other potentially required environment variables, have to be set here. The dummy file does not need to exist, it is never read, but some file name has to be supplied.

  3. Wait a few seconds to allow the server to start up. It prints a message like Server started successfully on <address> when it is ready.

  4. While the server is running, run a client to instruct the server to verify a specific file:

    nagini_client path/to/file.py

Model Context Protocol (MCP) Server

Nagini ships an MCP server that exposes verification to AI agents and MCP-capable editors (e.g. Claude Code, Claude Desktop, Cursor) over stdio. Through it, an agent can verify entire files, individual methods, or inline snippets and receive structured diagnostics (error positions, messages, and optional counterexamples).

  1. Install Nagini with the MCP dependencies:

    pip install "nagini[mcp]"

    As with normal command-line use, a Java installation is required. The Z3 and Viper JAR binaries needed for verification are bundled with Nagini, so you do not need to supply them separately. If Java is not found automatically, set the JAVA_HOME environment variable to point to your Java installation.

  2. The server is launched via the nagini_mcp entry point and communicates over stdio, so it is normally started by the MCP client rather than by hand. Configure your client to run it, passing JAVA_HOME through the environment if needed. For example:

    {
      "mcpServers": {
        "nagini": {
          "command": "nagini_mcp",
          "env": { "JAVA_HOME": "/path/to/your/java" }
        }
      }
    }

    Use the absolute path to the nagini_mcp executable (e.g. the one inside your virtual environment) if it is not on the client’s PATH. The server uses the faster in-process ViperServer backend by default and accepts the same configuration options as the command line (e.g. --verifier); run nagini_mcp --help to see them.

The server exposes the following tools: verify_file, verify_method, verify_snippet, configure (change verification options at runtime), cancel, and flush_cache. See the wiki for information on how to write specifications in Nagini.

Alternative Viper Versions

To use a more recent or custom version of the Viper infrastructure, follow the instructions here. Look for sbt assembly to find instructions for packaging the required JAR files. Use the parameters mentioned above to instruct Nagini to use your custom Viper version.

Troubleshooting

  1. On Windows: During the setup, you get an error like Microsoft Visual C++ 14.0 is required. or Unable to fnd vcvarsall.bat:

    Python cannot find the required Visual Studio C++ installation, make sure you have either installed the Build Tools or checked the “Common Tools” option in your regular Visual Studio installation (see above).

  2. While verifying a file, you get a stack trace ending with something like No matching overloads found:

    The version of Viper you’re using does not match your version of Nagini. Try updating both to the newest version.

  3. Nagini cannot prove trivial properties about the return values of functions:

    This is likely due to a lack of specifications, see the discussion in the General Contracts section of the wiki.

Publications on Nagini

The following papers describe verification techniques implemented in Nagini:

Published Work Using Nagini

The following papers and theses have used Nagini to verify Python programs:

Metadata

Release files for nagini 1.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nagini 1.3.1
File Size Uploaded Provenance Actions
nagini-1.3.1.tar.gz 80.3 MB Without provenance Details for nagini-1.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nagini 1.3.1
File Interpreter ABI Platform Actions
nagini-1.3.1-py3-none-any.whl Python 3 none any Details for nagini-1.3.1-py3-none-any.whl

Total release size: 160.8 MB

Release files / nagini-1.3.1.tar.gz

Download URL nagini-1.3.1.tar.gz
Size 80.3 MB
Tags Source
SHA-256 checksum
How to use checksums
3dbaf18a64ff641ea48e75dc838627173bca10f6be449a4044f0986f17ff2ea5
BLAKE2b-256 checksum
How to use checksums
68b8e538cbfadeb8e61af7e06cb81e77d93c0fab5e227130b0bd962cabf0bc2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / nagini-1.3.1-py3-none-any.whl

Download URL nagini-1.3.1-py3-none-any.whl
Size 80.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
56d85c9a55baa3a769d849138ff2e49c0a1627424e680aea96f76fce96c4206c
BLAKE2b-256 checksum
How to use checksums
96bbe30f137db9423bd71b89682093bbeade8b4647f7d479e6a713858751a1d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Security for nagini 1.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page