Three safe tools for agentic code analysis
Project description
readonly-fs-tools
Three safe tools for agentic code analysis: Globber, Grepper, and Viewer.
This package provides security-focused, sandboxed file operations designed specifically for AI agents and automated code analysis workflows. Each tool enforces strict boundaries to prevent unauthorized file access while enabling powerful code exploration capabilities.
Installation
# Add to your project
uv add readonly-fs-tools
Quick Start
from readonly_fs_tools import Sandbox, Globber, Grepper, Viewer, OutputBudget
from pathlib import Path
# Create a sandbox configuration
sandbox = Sandbox(
sandbox_dir=Path("/path/to/your/project"),
blocked_files=["*.secret", "private/*"],
allow_hidden=False
)
# Set up output budget to limit response sizes
budget = OutputBudget(max_chars=10000)
# 1. Find files with glob patterns
globber = Globber.from_sandbox(sandbox)
glob_result = globber.glob("**/*.py", budget)
print(f"Found {len(glob_result.paths)} Python files")
# 2. Search file contents with regex
grepper = Grepper.from_sandbox(sandbox)
grep_result = grepper.grep(r"class \w+", "**/*.py", budget)
for match in grep_result.matches:
print(f"{match.path}:{match.line_number}: {match.line}")
# 3. View file contents safely
viewer = Viewer.from_sandbox(sandbox)
view_result = viewer.view("src/main.py", budget)
print(view_result.content.text)
Core Components
Security Model
All tools are executed in the context of a Sandbox which enforces:
- Sandbox directory constraints - Operations limited to specified directory
- File blocklist - Pattern-based file exclusion (e.g.,
*.secret,private/*) - Hidden file controls - Optional access to dotfiles and hidden directories (off by default)
In addition, each tool supports:
- Output size limits - Configurable via
OutputBudgetto constrain token usage - Streaming operations - Files are processed in a memory-efficient manner, allowing for large files to be handled safely
Tools
Globber - Safe file pattern matching
- Uses glob patterns like
**/*.pyorsrc/**/*.{js,ts} - Respects sandbox boundaries and blocklists
Grepper - Safe content search
- Regex-based content search across files
- Pattern matching with full regex syntax support
- Returns matches with file paths, line numbers, and the full matched line for context
Viewer - Safe file viewing
- Bounded file content access with configurable limits
- Support for line ranges and content windows
- Safe handling of binary files and large files
Key Types
# Pattern validation
GlobPattern # Validated glob patterns
RegexPattern # Validated regex patterns
# File access
FileWindow # Line-based file access windows
FileContent # Safe file content representation
FileReadResult # Results with metadata
# Configuration
Sandbox # Security boundary configuration
OutputBudget # Output size limiting
Development
This project uses uv for dependency management.
uv sync --dev
Code Quality
uv run ruff check --fix # Lint code
uv run ruff format # Format code
uv run mypy --strict . # Type checking
Testing
uv run pytest # Run all tests
uv run pytest tests/test_specific_file.py # Run specific tests
Architecture
The package implements a three-layer security model:
- Sandbox - Directory and file access controls
- Budget - Resource usage limits
- Validation - Input pattern validation and output sanitization
All operations are designed to be safe for automated/AI agent use while providing the file system access needed for code analysis tasks.
Generative AI disclaimer
This package was designed by a human developer, with assistance from generative AI. The code however was generated almost entirely by generative AI. The security model and design principles were carefully crafted to ensure safety and reliability for agentic code/filesystem analysis tasks. If you find any issues or have suggestions, please open an issue on GitHub.
License
MIT License - see LICENSE for details.
Links
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 readonly_fs_tools-0.2.0.tar.gz.
File metadata
- Download URL: readonly_fs_tools-0.2.0.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abcb837b08c2825a3899908166c888bf45c08198b2e59553766c337dba7649a1
|
|
| MD5 |
fa7f8a37b4cf8bb3d14697dd9bc08bf8
|
|
| BLAKE2b-256 |
4a8eac46fd5a38d6924c411738692590d4dc57feadfffdc467bdf48b7f4543d4
|
File details
Details for the file readonly_fs_tools-0.2.0-py3-none-any.whl.
File metadata
- Download URL: readonly_fs_tools-0.2.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b9c0a22e7b37e4aa884a314bc644a2f7708eb32c8c98e0f877a7013428ba9d7
|
|
| MD5 |
59f0f0495050a8271559e6ecde1eeeb0
|
|
| BLAKE2b-256 |
7253dfc0e75bc2a5ddbbda07324f5408b884e6edbbdca7497c64a769e03cb866
|