PyRIT Shell - Interactive Command Line#
PyRIT Shell provides an interactive REPL (Read-Eval-Print Loop) for running AI red teaming scenarios with fast execution and session-based result tracking.
Quick Start#
Start the shell:
pyrit_shell
With startup options:
# Set default database for all runs
pyrit_shell --database InMemory
# Set default log level
pyrit_shell --log-level DEBUG
# Load initializers at startup
pyrit_shell --initializers openai_objective_target
# Load custom initialization scripts
pyrit_shell --initialization-scripts ./my_config.py
Available Commands#
Once in the shell, you have access to:
Command |
Description |
|---|---|
|
List all available scenarios |
|
List all available initializers |
|
Run a scenario with optional parameters |
|
List all previous scenario runs in this session |
|
Print detailed results for scenario run(s) |
|
Show help for a command |
|
Clear the screen |
|
Exit the shell |
Running Scenarios#
The run command executes scenarios with the same options as pyrit_scan:
Basic Usage#
pyrit> run foundry_scenario --initializers openai_objective_target
With Strategies#
pyrit> run encoding_scenario --initializers openai_objective_target --strategies base64 rot13
pyrit> run foundry_scenario --initializers openai_objective_target -s jailbreak crescendo
With Runtime Parameters#
# Set concurrency and retries
pyrit> run foundry_scenario --initializers openai_objective_target --max-concurrency 10 --max-retries 3
# Add memory labels for tracking
pyrit> run encoding_scenario --initializers openai_objective_target --memory-labels '{\"experiment\":\"test1\",\"version\":\"v2\"}'
Override Defaults Per-Run#
# Override database and log level for this run only
pyrit> run encoding_scenario --initializers openai_objective_target --database InMemory --log-level DEBUG
Run Command Options#
--initializers <name> ... Built-in initializers to run before the scenario (REQUIRED)
--initialization-scripts <...> Custom Python scripts to run before the scenario (alternative)
--strategies, -s <s1> <s2> ... Strategy names to use
--max-concurrency <N> Maximum concurrent operations
--max-retries <N> Maximum retry attempts
--memory-labels <JSON> JSON string of labels
--database <type> Override default database (InMemory, SQLite, AzureSQL)
--log-level <level> Override default log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
Session History#
Track and review all scenario runs in your session:
# Show all runs from this session
pyrit> scenario-history
# Print details of the most recent run
pyrit> print-scenario
# Print details of a specific run (by number from history)
pyrit> print-scenario 1
# Print all runs
pyrit> print-scenario
Example output:
pyrit> scenario-history
Scenario Run History:
================================================================================
1) foundry_scenario --initializers openai_objective_target --strategies base64
2) encoding_scenario --initializers openai_objective_target --strategies rot13
3) foundry_scenario --initializers openai_objective_target -s jailbreak
================================================================================
Total runs: 3
Use 'print-scenario <number>' to view detailed results for a specific run.
Interactive Exploration#
The shell excels at interactive testing workflows:
# Start shell with defaults
pyrit_shell --database InMemory --initializers openai_objective_target
# Quick exploration
pyrit> list-scenarios
pyrit> run encoding_scenario --strategies base64
pyrit> run encoding_scenario --strategies rot13
pyrit> run encoding_scenario --strategies morse_code
# Review and compare
pyrit> scenario-history
pyrit> print-scenario 1
pyrit> print-scenario 2
Shell Benefits#
Fast Execution: PyRIT modules load once at startup (typically 5-10 seconds), making subsequent commands instant
Session Tracking: All runs are stored in history for easy comparison
Interactive Workflow: Perfect for iterative testing and debugging
Persistent Context: Default settings apply across multiple runs
Tab Completion: Command and argument completion (if supported by your terminal)
Tips#
Set defaults at startup to avoid repeating options:
pyrit_shell --database InMemory --log-level INFO
Use short strategy aliases with
-s:pyrit> run foundry_scenario --initializers openai_objective_target -s base64 rot13
Review history regularly to track what you’ve tested:
pyrit> scenario-historyPrint specific results to compare outcomes:
pyrit> print-scenario 1 # baseline run pyrit> print-scenario 3 # modified run
Exit the Shell#
pyrit> exit
Or use quit or q.