Quickstart |
Pre-Generated Safety Experiences |
Generate Your Own Safety Experiences |
Extend to New Tools |
Safety Benchmark |
Citation
ToolShield is a training-free, tool-agnostic defense for AI agents that use MCP tools. Just pip install toolshield and a single command guards your coding agent with safety experiences — no API keys, no sandbox setup, no fine-tuning. Reduces attack success rate by 30% on average.
Quickstart
pip install toolshield
Use Pre-generated Experiences
We ship safety experiences for 6 models across 5 tools, with plug-and-play support for 5 coding agents:
Inject them in one command — no need to know where files are installed:
# For Claude Code (filesystem example)
toolshield import --exp-file filesystem-mcp.json --agent claude_code
# For Codex (postgres example)
toolshield import --exp-file postgres-mcp.json --agent codex
# For OpenClaw (terminal example)
toolshield import --exp-file terminal-mcp.json --agent openclaw
# For Cursor (playwright example)
toolshield import --exp-file playwright-mcp.json --agent cursor
# For OpenHands (notion example)
toolshield import --exp-file notion-mcp.json --agent openhands
Use experiences from a different model with --model:
toolshield import --exp-file filesystem-mcp.json --model gpt-5.2 --agent claude_code
Or import all bundled experiences (all 5 tools) in one shot:
toolshield import --all --agent claude_code
You can also import multiple experience files individually:
toolshield import --exp-file filesystem-mcp.json --agent claude_code
toolshield import --exp-file terminal-mcp.json --agent claude_code
toolshield import --exp-file postgres-mcp.json --agent claude_code
See all available bundled experiences:
toolshield list
This appends safety guidelines to your agent's context file (~/.claude/CLAUDE.md, ~/.codex/AGENTS.md, ~/.openclaw/workspace/AGENTS.md, Cursor's global user rules, or ~/.openhands/microagents/toolshield.md). To remove them:
toolshield unload --agent claude_code
Available bundled experiences (run toolshield list to see all):
| Model | |||||
|---|---|---|---|---|---|
claude-sonnet-4.5 |
✅ | ✅ | ✅ | ✅ | ✅ |
gpt-5.2 |
✅ | ✅ | ✅ | ✅ | ✅ |
deepseek-v3.2 |
✅ | ✅ | ✅ | ✅ | ✅ |
gemini-3-flash-preview |
✅ | ✅ | ✅ | ✅ | ✅ |
qwen3-coder-plus |
✅ | ✅ | ✅ | ✅ | ✅ |
seed-1.6 |
✅ | ✅ | ✅ | ✅ | ✅ |
More plug-and-play experiences for additional tools coming soon (including Toolathlon support)! Have a tool you'd like covered? Open an issue.
Generate Your Own Safety Experiences
Point ToolShield at any running MCP server to generate custom safety experiences:
export TOOLSHIELD_MODEL_NAME="anthropic/claude-sonnet-4.5"
export OPENROUTER_API_KEY="your-key"
# Full pipeline: inspect → generate safety tree → test → distill → inject
toolshield \
--mcp_name postgres \
--mcp_server http://localhost:9091 \
--output_path output/postgres \
--agent codex
Or generate without injecting (useful for review):
toolshield generate \
--mcp_name postgres \
--mcp_server http://localhost:9091 \
--output_path output/postgres
Auto-discover Local MCP Servers
Automatically scan localhost for running MCP servers, run the full pipeline for each, and inject the results:
toolshield auto --agent codex
This scans ports 8000-10000 by default (configurable with --start-port / --end-port).
Extend to New Tools
ToolShield works with any MCP server that has an SSE endpoint:
toolshield generate \
--mcp_name your_custom_tool \
--mcp_server http://localhost:PORT \
--output_path output/your_custom_tool
MT-AgentRisk Benchmark
We also release MT-AgentRisk, a benchmark of 365 harmful tasks across 5 MCP tools, transformed into multi-turn attack sequences. See agentrisk/README.md for full evaluation setup.
Quick evaluation:
# 1. Download benchmark tasks
git clone https://huggingface.co/datasets/CHATS-Lab/MT-AgentRisk
cp -r MT-AgentRisk/workspaces/* workspaces/
# 2. Run a single task (requires OpenHands setup — see agentrisk/README.md)
python agentrisk/run_eval.py \
--task-path workspaces/terminal/multi_turn_tasks/multi-turn_root-remove \
--agent-llm-config agent \
--env-llm-config env \
--outputs-path output/eval \
--server-hostname localhost
Add --use-experience <path> to evaluate with ToolShield defense.
Repository Layout
ToolShield/
├── toolshield/ # pip-installable defense package
│ └── experiences/ # bundled safety experiences (6 models × 5 tools)
├── agentrisk/ # evaluation framework (see agentrisk/README.md)
├── workspaces/ # MT-AgentRisk task data (from HuggingFace)
├── docker/ # Dockerfiles and compose
└── scripts/ # experiment reproduction guides
Acknowledgments
We thank the authors of the following projects for their contributions:
Citation
@misc{li2026unsaferturnsbenchmarkingdefending,
title={Unsafer in Many Turns: Benchmarking and Defending Multi-Turn Safety Risks in Tool-Using Agents},
author={Xu Li and Simon Yu and Minzhou Pan and Yiyou Sun and Bo Li and Dawn Song and Xue Lin and Weiyan Shi},
year={2026},
eprint={2602.13379},
archivePrefix={arXiv},
primaryClass={cs.CR},
url={https://arxiv.org/abs/2602.13379},
}
License
MIT
Metadata
Release files for toolshield 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| toolshield-0.1.3.tar.gz | 9.8 MB | Without provenance | Details for toolshield-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| toolshield-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for toolshield-0.1.3-py3-none-any.whl |
Total release size: 9.9 MB
Release files / toolshield-0.1.3.tar.gz
| Download URL | toolshield-0.1.3.tar.gz |
|---|---|
| Size | 9.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f680c20398aeb5f95820c25e70c9fdb97ff416b4e033422859f3173570cd3826
|
|
BLAKE2b-256 checksum How to use checksums |
6659a002a9e3100635b57fdbd1e2af3a810239a24811f059283d48cfecebc402
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / toolshield-0.1.3-py3-none-any.whl
| Download URL | toolshield-0.1.3-py3-none-any.whl |
|---|---|
| Size | 84.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aa52be93bbc2c552529254482dc0f6a7493325b8becc2b897b3cb80be4b23fd3
|
|
BLAKE2b-256 checksum How to use checksums |
22912c55455c01a4f7e303f22a4a03538a8630f37824f36cb6c1d9a0252dc34c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Security for toolshield 0.1.3
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.