veereshdev/prompt-injection-env
title: Prompt Injection Defense Environment emoji: ??? colorFrom: red colorTo: purple sdk: docker pinned: false license: mit tags:
- openenv
- security
- prompt-injection ---
Prompt Injection Defense Environment
An OpenEnv-compatible reinforcement-learning environment where an AI agent learns to detect, classify, and neutralise prompt injection attacks embedded in documents — addressing OWASP Top 10 for LLM Applications, Risk #1.
Why this matters
Prompt injection is the most critical unsolved security problem in AI today. Every RAG system, AI email assistant, and AI web browser is currently vulnerable. No standardised training environment existed — until now.
Environment Description
The agent acts as a security layer reviewing documents before they reach a downstream LLM. It must identify whether a document contains an injection, classify the attack type, and return a sanitised version with the attack removed and all legitimate content preserved.
Action Space
# Single-document tasks (easy, medium)
Action(
is_injection=True,
attack_type="direct_injection",
sanitised_content="...cleaned document...",
confidence=0.95,
explanation="Found explicit override instruction at end of document."
)
# Multi-document task (hard)
Action(
document_analyses=[
{"is_injection": False, "attack_type": "no_injection", "sanitised_content": "...", ...},
{"is_injection": True, "attack_type": "semantic_injection", "sanitised_content": "...", ...},
{"is_injection": True, "attack_type": "multi_hop_injection", "sanitised_content": "...", ...},
]
)Observation Space
Attack Taxonomy
Tasks
Reward Function
Penalties: over-sanitisation (removing benign content) reduces score.
Setup & Usage
Local
pip install -r requirements.txt
set HF_TOKEN=hf_your_token_here
set API_BASE_URL=https://router.huggingface.co/v1
set MODEL_NAME=meta-llama/Llama-3.1-8B-Instruct
python inference.pyDocker
docker build -t prompt-injection-env .
docker run -e HF_TOKEN=hf_your_token -e MODEL_NAME=meta-llama/Llama-3.1-8B-Instruct prompt-injection-envProject Structure
prompt-injection-env/
├── inference.py # Mandatory baseline inference script
├── Dockerfile
├── requirements.txt
├── openenv.yaml
├── README.md
└── prompt_injection_env/
├── __init__.py
├── env.py # Main environment (reset/step/state)
├── corpus.py # Attack corpus and document builders
└── graders.py # Deterministic scoring logic