Sandboxed execution environments for AI agents with permission management and audit logging
Project description
agent-sandbox-sdk
Give AI agents controlled system access without the security nightmares or container overhead.
What is this?
agent-sandbox-sdk is a Python SDK that wraps AI agent functions in isolated execution environments with fine-grained permission controls, resource limits, and comprehensive audit logging. Instead of giving LLMs unrestricted system access or wrestling with Docker containers, you get a simple decorator-based API that makes sandboxing as easy as @sandbox(permissions=[...]).
Perfect for LangChain tools, CrewAI agents, or any AI system that needs to touch the filesystem, network, or spawn processes safely.
Features
- Decorator-based API – Wrap any function with
@sandbox()for instant isolation - Fine-grained permissions – Whitelist specific filesystem paths, network domains, and process types
- Resource limits – Cap CPU time, memory usage, and disk writes per execution
- Comprehensive audit logging – Track every action with timestamps, results, and resource consumption
- Real-time monitoring – Built-in dashboard for observing agent behavior across sessions
- Framework integrations – Drop-in support for LangChain, CrewAI, and AutoGPT
- Webhook support – Get notified on permission violations or resource threshold breaches
- Cross-platform – Works on Linux, macOS, and Windows
Quick Start
Installation
pip install agent-sandbox-sdk
Basic Usage
from agent_sandbox import sandbox, FileSystemPermission, NetworkPermission
@sandbox(
permissions=[
FileSystemPermission(read=["/data"], write=["/tmp/output"]),
NetworkPermission(domains=["api.example.com"])
],
max_execution_time=30, # seconds
max_memory_mb=512
)
def agent_task(query: str):
# Agent code runs in isolated environment
with open("/data/docs.txt") as f:
content = f.read()
# Network access only to whitelisted domains
response = requests.get("https://api.example.com/search")
return process_results(content, response.json())
# Execute safely
result = agent_task("analyze sales data")
LangChain Integration
from langchain.agents import Tool
from agent_sandbox.integrations.langchain import SandboxedTool
# Wrap any LangChain tool with sandbox protection
safe_tool = SandboxedTool(
tool=Tool(
name="file_reader",
func=read_file,
description="Read files from disk"
),
permissions=[FileSystemPermission(read=["/safe/path"])],
max_execution_time=10
)
agent = initialize_agent([safe_tool], llm, agent="zero-shot-react-description")
Monitoring Dashboard
# Start the monitoring dashboard
agent-sandbox dashboard --port 8080
Access at http://localhost:8080 to view:
- Real-time agent execution logs
- Resource usage graphs
- Permission violation alerts
- Audit trail exports
Usage Examples
Resource Monitoring
from agent_sandbox import sandbox, get_execution_stats
@sandbox(max_memory_mb=256, max_execution_time=60)
def data_processor(files: list):
results = []
for file in files:
results.append(process_file(file))
return results
result = data_processor(["data1.csv", "data2.csv"])
stats = get_execution_stats()
print(f"Peak memory: {stats.peak_memory_mb}MB")
print(f"Execution time: {stats.execution_time}s")
print(f"Files accessed: {stats.files_accessed}")
Audit Logging
from agent_sandbox import sandbox, AuditLogger
# Configure audit logger with webhook
logger = AuditLogger(
log_file="/var/log/agents/audit.jsonl",
webhook_url="https://your-server.com/audit-webhook",
alert_on_violation=True
)
@sandbox(
permissions=[NetworkPermission(domains=["safe-api.com"])],
audit_logger=logger
)
def agent_action():
# All actions logged automatically
response = requests.get("https://safe-api.com/data")
return response.json()
CrewAI Integration
from crewai import Agent, Task, Crew
from agent_sandbox.integrations.crewai import SandboxedAgent
# Create sandboxed CrewAI agent
analyst = SandboxedAgent(
role="Data Analyst",
goal="Analyze sales data",
backstory="Expert in data analysis",
permissions=[
FileSystemPermission(read=["/data/sales"]),
NetworkPermission(domains=["api.salesforce.com"])
],
max_execution_time=120
)
crew = Crew(agents=[analyst], tasks=[...])
Tech Stack
- Core: Python 3.8+ with asyncio for concurrent execution
- Isolation: Platform-specific syscall monitoring (seccomp on Linux, Seatbelt on macOS)
- Dashboard: FastAPI backend with React frontend
- Audit Storage: SQLite for local logging with optional PostgreSQL support
- Monitoring: Prometheus metrics export for production observability
Configuration
Create sandbox_config.yaml:
default_permissions:
filesystem:
read: ["/data/public"]
write: ["/tmp"]
network:
domains: ["*.safe-api.com"]
resource_limits:
max_execution_time: 60
max_memory_mb: 512
max_disk_write_mb: 100
audit:
enabled: true
log_file: "/var/log/agent_sandbox/audit.log"
webhook_url: "https://monitoring.example.com/webhook"
dashboard:
port: 8080
auth_required: true
CLI Commands
# Start monitoring dashboard
agent-sandbox dashboard
# View audit logs
agent-sandbox logs --tail 100 --filter "violation"
# Export audit report
agent-sandbox export --format json --output report.json
# Validate permissions config
agent-sandbox validate config.yaml
License
MIT License - see LICENSE file for details.
Security Note: This SDK provides defense-in-depth for AI agent execution but should not be the only security measure. Always follow the principle of least privilege and conduct security reviews of agent code.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zachos_agent_sandbox_sdk-0.1.0.tar.gz.
File metadata
- Download URL: zachos_agent_sandbox_sdk-0.1.0.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43b624dba84919688c0fb0cf282bd6b8defd2e25888f44e9b7ea182a3eb18e8f
|
|
| MD5 |
9186603f965f7f27e7fa943056630757
|
|
| BLAKE2b-256 |
2cbbb49fb1e9ec9ec62ac08229fd3d1928d2d1f9f6c4c59f05f05350a21237d9
|
File details
Details for the file zachos_agent_sandbox_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: zachos_agent_sandbox_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8f27cd775e23520a54656ee2165521c1df2a429137447c64bfbdd90f04c8606
|
|
| MD5 |
d6bf76ec58a8ca46b9c9078bbb303132
|
|
| BLAKE2b-256 |
9872ce911f29529cb706d2ba5ce2153ad995f17aadecef4d75cc32dfd7064938
|