Attacks on machine learning models have been extensively studied through stateless optimization. In this paper, we demonstrate how a reinforcement learning (RL) agent can learn a new class of attack algorithms that generate adversarial samples. Unlike traditional adversarial machine learning (AML) methods that craft adversarial samples independently, our RL-based approach retains and exploits past attack experience to improve the effectiveness and efficiency of future attacks. We formulate adversarial sample generation as a Markov Decision Process and evaluate RL’s ability to (a) learn effective and efficient attack strategies and (b) compete with state-of-the-art AML. On two image classification benchmarks, our agent increases attack success rate by up to 13.2% and decreases the average number of victim model queries per attack by up to 16.9% from the start to the end of training. In a head-to-head comparison with state-of-the-art image attacks, our approach enables an adversary to generate adversarial samples with 17% more success on unseen inputs post-training. From a security perspective, this work demonstrates a powerful new attack vector that uses RL to train agents that attack ML models efficiently and at scale.
This repository contains code and resources for training and evaluating adversarial agents against victim models in a controlled environment. The following instructions will guide you through setting up the environment, training victim models, training adversarial agents, and evaluating their performance.
- Setting Up Docker and Dependencies
- Training Victim Models
- Training Adversarial Agents
- Evaluating Adversarial Agents
To ensure a consistent and reproducible environment, we use Docker. Follow these steps to set up the environment:
-
Install Docker:
- Download and install Docker from https://www.docker.com/.
- Verify the installation:
docker --version
-
Build the Docker Image:
- Navigate to the project directory:
cd ./adversarial-agents - Build the Docker image:
docker build -t adversarial-agents .
- Navigate to the project directory:
-
Run the Docker Container:
- Start a container with the built image:
docker run -it --rm -v $(pwd):/workspace adversarial-agents
- Start a container with the built image:
-
Install Additional Dependencies (if needed):
- Inside the container, install Python dependencies:
pip install -r requirements.txt
- Inside the container, install Python dependencies:
Victim models are the targets for adversarial attacks. Follow these steps to train and save them for experimentation:
-
Training the Victim Model:
- Run the training script:
python train_victim_model.py --dataset cifar10 --epochs 50
- Adjust the parameters (
--dataset,--model,--epochs,--lr,--batch-size) as needed for your experiments.
- Run the training script:
-
Save the Model:
- The trained model will automatically be saved in the
victim_models/directory with a filename like<dataset>+<model>.pth
- The trained model will automatically be saved in the
Adversarial agents are trained using reinforcement learning (RL) to improve subsequent attacks on victim models. Follow these steps to train your adversarial agents:
-
Train the Adversarial Agent:
-
Run the training script:
python train_agent.py --dataset cifar10 --victim_model resnet50 --rl_attack_type RLMaxLoss --epsilon 0.3 --N 5 --theta 0.05 --training_steps 5000000 --label rlmaxloss_agent
-
Adjust the parameters (
--dataset,--victim_model,--rl_attack_type,--epsilon,--N,--theta,--training_steps,--label) as needed for your experiments. -
The
--rl_attack_typecan be set toRLMaxLossorRLMinNormdepending on the attack strategy you want to implement (described in 'Learning Adversarial Policies' section of the paper).
-
-
Monitor Training:
-
Training logs will be saved in the
learning_results/directory. You can monitor the training progress by checking these logs. -
learning_results/episodic.csv- Contains the episodic rewards, distortion, queries, original label
$y$ , and prediction$Z(x_t)$ - PPO updates happen every 4096 queries, which can be added as a column post-training by adding a running sum of the queries and floor dividing by 4096.
- Contains the episodic rewards, distortion, queries, original label
-
learning_results/progress.csv- Contains default training logs from StableBaselines3 for RL metrics. For more information, refer to the logger output section of the StableBaselines3 documentation here.
-
-
Save the Agent:
- The trained adversarial agent will be saved in the
agents/directory with a filename like<label>.pth. - For example, if you set
--label rlmaxloss_agent, the agent will be saved asagents/rlmaxloss_agent.pth.
- The trained adversarial agent will be saved in the
Evaluate the performance of adversarial agents against victim models:
-
Run Adversarial Agent Evaluation:
- Execute the evaluation script:
python evaluate_agent.py --dataset cifar10 --victim_model resnet50 --rl_attack_type RLMaxLoss --epsilon 0.3 --N 5 --theta 0.05 --agent_file ./agents/rlmaxloss_agent.pth
-
Note: Attack parameters (
--victim_model,--rl_attack_type,--epsilon,--N,--theta) should match those used during training for consistency.
- Execute the evaluation script:
-
Analyze Adversarial Agents Results:
- The evaluation logs will be saved in the
evaluation_results/directory. -
evaluation_results/episodic.csv- Contains the episodic rewards, distortion, queries, original label
$y$ , and prediction$Z(x_t)$ .
- Contains the episodic rewards, distortion, queries, original label
- The evaluation logs will be saved in the
If you find this work useful, please cite our paper:
@inproceedings{adversarialagents2026,
title = {Adversarial Agents: Black-Box Evasion Attacks with Reinforcement Learning},
author = {Kyle Domico and Jean-Charles Noirot Ferrand and Ryan Sheatsley and Eric Pauley and Josiah Hanna and Patrick McDaniel},
booktitle = {Findings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
year = {2026}
}