22.1.3. Installing basic tools

2025.10.06.
AI Security Blog

With your virtual environment activated, you have a clean slate—an isolated workspace ready to be equipped. An effective AI Red Teamer’s toolkit is not about having every possible library, but about having the *right* foundational tools for analysis, interaction, and attack simulation. This chapter focuses on installing that essential first layer.

We will install a curated set of Python libraries that form the bedrock for most AI security tasks, from data manipulation to crafting adversarial examples.

Kapcsolati űrlap - EN

Do you have a question about AI Security? Reach out to us here:

The Foundational Toolkit

Your initial toolkit should cover four primary domains: data handling, machine learning framework interaction, specialized security testing, and basic utilities. The table below summarizes the core libraries we’ll install and their roles in your red teaming activities.

Category Library Primary Role in AI Red Teaming
Data Manipulation NumPy & Pandas Essential for handling numerical data, manipulating datasets, and preparing payloads for model input.
ML Frameworks scikit-learn, tensorflow Allows you to build surrogate models, understand common ML pipelines, and interact with target models built on these popular frameworks.
Adversarial Libraries adversarial-robustness-toolbox (ART) A comprehensive library for crafting and evaluating adversarial attacks (evasion, poisoning) and defenses.
Adversarial Libraries textattack A powerful framework specifically for generating adversarial examples against NLP models.
Utilities requests, jupyter requests is for interacting with model APIs. jupyter provides an interactive environment for research and testing.

Installation and Verification

Assuming your virtual environment from the previous chapter is active, you can install all these tools using Python’s package manager, pip. We will install them in a single command for efficiency. Note that we are specifying TensorFlow here, but you could substitute or add torch if your target environments primarily use PyTorch.

# Ensure your virtual environment is active before running this
python -m pip install 
  numpy                  # For numerical operations
  pandas                 # For data analysis and manipulation
  scikit-learn           # For general machine learning tasks
  tensorflow             # Core deep learning framework
  adversarial-robustness-toolbox  # Key adversarial attack library
  textattack             # For NLP-specific attacks
  requests               # For interacting with web APIs
  jupyterlab              # For interactive development notebooks

After the installation process completes, a quick verification step ensures all packages are correctly installed and accessible within your environment. You can run a simple Python command to attempt importing the core libraries.

# Run this command in your terminal
python -c "import numpy; import pandas; import sklearn; import tensorflow as tf; import art; import textattack; print('Verification successful: Core libraries imported.')"

If this command executes without any ModuleNotFoundError messages and prints the success message, your foundational toolkit is ready.

Best Practice: Managing Dependencies

As you progress, you will install more specialized tools. It is a critical professional habit to keep track of your project’s dependencies. This ensures your environment is reproducible by you or your teammates.

Once your core tools are installed and verified, generate a requirements.txt file. This file is a snapshot of your environment’s packages and their exact versions.

Creating a Requirements File

The pip freeze command outputs a list of all installed packages in the environment. You can redirect this output to a file.

# This command creates or overwrites requirements.txt
pip freeze > requirements.txt

Later, you or someone else can replicate this exact environment in a new virtual environment using pip install -r requirements.txt. This practice is fundamental for consistent and reliable security testing.

You have now successfully transformed a bare virtual environment into a capable launchpad for AI red teaming operations. The next step is to consider the security of your own testing machine by establishing a sandbox.