This repository contains the source code and dataset for the paper "Evaluating Privilege Usage of Agents on Real-World Tools".
GrantBox is a security evaluation framework designed to systematically assess how autonomous agents handle privilege usage when interacting with real-world tools and services. The framework provides a sandbox environment that integrates real-world MCP servers with privilege-sensitive tools, enabling comprehensive security evaluation of agents across cloud infrastructure, databases, email services, and other critical systems.
System Requirements:
- OS: Linux (Ubuntu/Debian recommended) or macOS
- uv: Lightweight tool for managing Python dependencies and syncing reproducible environments
- Docker: Installed and running
- Git: For cloning the repository
1. Install Python Dependencies
Using uv (Recommended)
# Install project dependencies
uv sync2. Build Base Docker Image
Build the base Docker image that includes all runtime code (interceptors, proxy, replay):
./src/scripts/build_base_image.shThis will:
- Create
mcp-sandbox-base:latestimage - Pre-install Python, Node.js, uv, iptables
- Copy interceptors, proxy, and replay code into the image
Note: This step takes 2-5 minutes depending on your network speed.
3. Configure Container
Copy the container configuration file:
cp configs/container.example.yaml configs/container.yamlEdit configs/container.yaml to customize container settings as needed.
4. Configure Servers
Copy and edit the servers configuration:
cp configs/servers.example.json configs/servers.jsonEdit configs/servers.json to add your MCP servers. See configs/servers.example.json for examples.
The source code for the MCP servers can be accessed via this link. Extract the downloaded archive to the servers_source/ directory in the project root for deployment.
5. Configure Workflows
Copy and edit the workflows configuration:
cp configs/workflows.example.json configs/workflows.jsonEdit configs/workflows.json to define your workflows.
6. Set Up Environment Variables
Create a .env file in the project root:
# Model API keys
OPENAI_API_KEY=your-openai-key
ANTHROPIC_API_KEY=your-anthropic-key
DASHSCOPE_API_KEY=your-dashscope-key
GOOGLE_API_KEY=your-google-key
DEEPSEEK_API_KEY=your-deepseek-key
# Other configuration
LOG_LEVEL=INFO7. Verify Docker Setup
Test Docker access:
docker ps
docker images8. Configure Pipeline Mode
cp configs/react.example.yaml configs/react.yamlFirst, install dependencies:
uv syncThen run a workflow evaluation:
# Workflow mode (required)
# --config contains model and agent settings (mode, model vendor/name, kwargs)
uv run python main.py \
--config configs/react.yaml \
--workflows configs/workflows.json \
--workflow-id wf_notion_langfuse1. Configure Model and Provider
Edit the corresponding mode file (configs/react.yaml) to configure your model and provider settings.
2. Run Batch Experiments
Execute the following command to run batch experiments:
uv run python main.py \
--config configs/react.yaml \
--workflows configs/workflows_benign.json \
--attack-mode \
--injection-workflows configs/workflows_injection.json \
--injection-k 53. Evaluate a Single Workflow
To evaluate one benign workflow with a specific injection workflow:
uv run python main.py \
--config configs/react.yaml \
--workflows configs/workflows_benign.json \
--workflow-id system-prompt-audit-workflow \
--attack-mode \
--injection-workflows configs/workflows_injection.json \
--injection-id repo-purge-compliance-lureThe corresponding results will be stored in the logs/ directory.
The sandbox uses Docker containers to run MCP servers in isolation. Servers are deployed on-demand and accessed via container IP addresses.
# Deploy all servers
python src/scripts/configure_servers.py --config configs/react.yaml
# Check server status
python src/scripts/configure_servers.py --config configs/react.yaml --scan
# Remove all servers
python src/scripts/configure_servers.py --config configs/react.yaml --remove-all
# Deploy and start a specific server
python src/scripts/configure_servers.py --config configs/react.yaml --server <server_name>
# Stop a server
python src/scripts/configure_servers.py --config configs/react.yaml --server <server_name> --stop
# Remove a server's directory
python src/scripts/configure_servers.py --config configs/react.yaml --server <server_name> --removeSee src/container/CONTAINER_README.md for complete documentation on:
- Server deployment and configuration
- Container lifecycle management
- Port management and networking
- Base image usage and benefits
- Troubleshooting and best practices
The project structure is organized as follows:
-
configs/- Configuration files for the frameworkworkflows_benign.json- Benign workflow definitions for evaluationworkflows_injection.json- Malicious injection workflow definitions*.example.*- Example configuration templates
-
src/- Core source codeagents/- Agent implementations (ReAct, Plan-and-Execute, etc.)container/- Container management and sandbox infrastructuremodels/- LLM model integration and API clientsscripts/- Utility scriptstools/- Tool definitions and utilitiesattack_workflow_builder/- Workflow builderpipeline.py- Main evaluation pipelineconfig.py- Configuration loading and validation
-
servers_source/- MCP server source code repositories- Contains cloned or linked MCP server implementations (e.g.,
github-mcp-server,notion-mcp,email-mcp, etc.) - These servers are deployed into containers during evaluation
- Contains cloned or linked MCP server implementations (e.g.,
-
logs/- Evaluation results and execution logs- Stores workflow execution results, agent responses, and evaluation metrics
- Generated during evaluation runs
-
workflow_logs/- Detailed workflow execution logs- Contains per-workflow execution traces and debugging information
To access the container shell:
docker exec -it mcp-sandbox /bin/bash