amazon-science/task-tampering-prompt-injection
Python
Captured source
source ↗amazon-science/task-tampering-prompt-injection
Description: Beyond Instruction Override: Benchmarking Indirect Prompt Injection with Task-Tampering Attacks
Language: Python
License: NOASSERTION
Stars: 0
Forks: 0
Open issues: 3
Created: 2026-11-04T19:42:49Z
Pushed: 2026-11-06T08:45:57Z
Default branch: main
Fork: no
Archived: no
README:
Task-Tampering Prompt Injection
Research code and data for evaluating LLM agent robustness against task-tampering indirect prompt injections.
The repository includes the agent solver, three tool-use environments and their MCP servers, per-case scorers, runners for attack and defense experiments, and defense implementations. The benchmark data in [data/](data/README.md) contains 90 cases and 1,433 injection variants. Attach it before running evaluations (step 2 below).
Amazon-authored code and data are licensed CC BY-NC 4.0 ([LICENSE](LICENSE)). Third-party components retain their original licenses; see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
Release scope
This code is being released solely for academic and scientific reproducibility purposes, in support of the methods and findings described in the associated publication. Pull requests are not being accepted in order to maintain the code exactly as it was used in the paper.
1. Install
Requires Python 3.11+ and access to the models you want to run through any inspect_ai model provider. All model calls, including the scorer's LLM judge (see Scoring below), go through inspect_ai.
From the repository root:
python -m venv .venv && source .venv/bin/activate pip install -e . pip install -e ".[bedrock]" # only for bedrock/... models (adds aioboto3)
Install the SDK of any other provider you use (e.g. pip install openai) and set its credentials as described in the inspect_ai docs.
If pip tries to build numpy from source and fails, install a prebuilt wheel first (pip install --only-binary=numpy numpy), then rerun pip install -e ..
This installs inspect-ai at commit ee0dfdef8, together with pinned mcp and pyyaml.
Bedrock provider modification
The paper's models were called through Amazon Bedrock, with a slightly modified inspect_ai Bedrock provider. The runners install it automatically at import time (prompt_injection_benchmark/patches/). It only affects bedrock/... models; other providers are unaffected, and your installed inspect_ai files are not changed. The modification:
1. sends each tool-calling assistant turn as one Converse message (its text/reasoning followed by all of its tool calls) instead of one message per tool call; 2. keeps the reasoning signature so reasoning turns can be replayed; 3. disables ``-tag reasoning emulation.
patches/bedrock_ee0dfdef8.diff has the exact diff. The modification is applied only when the installed provider matches stock ee0dfdef8; with any other inspect_ai version it warns and does nothing. Set PIB_NO_BEDROCK_PATCH=1 to turn it off.
2. Attach the data
From the repository root, use the included data/ directory:
python -m prompt_injection_benchmark.scripts.link_data ./data # symlink python -m prompt_injection_benchmark.scripts.link_data --check
If symlinks are unavailable, use python -m prompt_injection_benchmark.scripts.link_data ./data --copy instead of the first command, then run --check. This creates prompt_injection_benchmark/environments/ and prompt_injection_benchmark/test_cases/variations/ inside the package, pointing at the included data. These generated paths are excluded from Git.
3. Run
Results are Inspect .eval files written under $PIB_OUTPUT_DIR (default ./pib_results).
Both runners take the model under evaluation as --model (required) and the scorer's LLM judge as --judge-model (or the LLM_CHECK_MODEL environment variable; required except for dry runs). Both are inspect_ai model ids (provider/model); the package does not ship a model list. The examples below use shell variables for them:
MODEL=/ # agent under evaluation JUDGE=/ # LLM judge for the scorer
Attack evaluation (no defense)
# what would run (environments, cases, variant counts) python -m prompt_injection_benchmark.scripts.run_eval --model "$MODEL" --dry-run # one case python -m prompt_injection_benchmark.scripts.run_eval --model "$MODEL" --judge-model "$JUDGE" \ --env devops --case A1 # a whole environment, one variant per primitive per case (plus each case's original) python -m prompt_injection_benchmark.scripts.run_eval --model "$MODEL" --judge-model "$JUDGE" \ --env productivity --max-per-primitive 1 # clean (no-injection) utility run, written to _no_injection/ python -m prompt_injection_benchmark.scripts.run_eval --model "$MODEL" --judge-model "$JUDGE" \ --env marketplace --no-injection
Without --env, every environment in scripts/config_eval.yaml is run. --resume skips samples that already have a score in the output directory. Output: $PIB_OUTPUT_DIR/attack_evaluation/evals///, where ` is the last path segment of the model id up to any :, with . replaced by _ (e.g. openai/gpt-4o -> gpt-4o). --no-injection runs go to _no_injection/ instead, so they are kept apart from the attacked original runs (both use the case id as the sample id); --output-suffix writes to _/` in either mode.
Defense evaluation
python -m prompt_injection_benchmark.scripts.run_defense --model "$MODEL" --dryrun python -m prompt_injection_benchmark.scripts.run_defense --model "$MODEL" --judge-model "$JUDGE" \ --defense progent_fullschema --env devops --case A1 # resume an interrupted run (skips completed samples) python -m prompt_injection_benchmark.scripts.run_defense --model "$MODEL" --judge-model "$JUDGE" \ --defense drift_full_guided --resume
--defense takes one of the names listed under Defenses below. Defaults come from scripts/config_defense.yaml. Output: $PIB_OUTPUT_DIR/defense_evaluation/evals////. camel_scoped and both Progent configurations embed their defense log in each sample's metadata and also write a per-sample JSON copy to defense_logs/ inside that directory.
config_defense.yaml sets max_per_primitive: 3: defense evaluations use up to three variants of each primitive per case (the case's original counts as its compound variant). Pass a larger --max-per-primitive to run more variants; to run every variant, set...
Excerpt shown — open the source for the full document.