Provides secure Python code execution in isolated Docker containers as a fallback sandbox backend, with support for dependency installation and persistent workspace state.
Analyzes directory structures while respecting .gitignore patterns to generate XML representations of codebases with intelligent summarization.
Directory Intelligence Tool
A comprehensive toolkit for analyzing directory structures and executing code in secure sandboxes. This project combines intelligent directory analysis with a secure execution environment for Programmatic Tool Calling (PTC).
Project Overview
This project provides two core capabilities:
Directory Analysis - Intelligently analyze directory structures with
.gitignoreawareness, automatic summarization, and robust error handlingSecure Code Execution - Execute Python code in isolated sandboxes with Daytona primary backend and Docker fallback
Architecture: Three integrated components work together to provide a complete solution for filesystem analysis and secure code execution.
Directory Intelligence Tool - Core directory analysis engine
FastMCP Server - Network-accessible interface to the directory tool
Sandbox Execution Engine - Secure, isolated Python execution environment
Components
1. Directory Intelligence Tool
File: src/directory_tool.py
Analyzes directory structures with intelligent summarization and .gitignore support.
Key Features:
Warning Taxonomy - Six warning types for different error conditions (unreadable_file, unreadable_directory, malformed_gitignore, broken_symlink, symlink_loop, too_many_warnings)
Smart Summarization - Automatically summarizes large directories (>50 files by default) to prevent XML bloat
Deterministic Ignore Precedence - Clear evaluation order: gitignore patterns → top-level dotdirs → normal scanning
XML Schema - Structured output with
<dir>,<file>,<summary>, and<warnings>elements
Quickstart:
Detailed Documentation → | Warning Taxonomy → | Summarization →
2. FastMCP Server
File: src/mcp_server.py
Network-accessible FastMCP service exposing the directory tool.
Key Features:
Configuration Management - Loads from
config/config.jsonwith environment variable overridesAutomatic Backend Detection - Daytona-first with Docker fallback for sandbox execution
Validation - Comprehensive config validation with clear error messages
Usage:
Note: Tool-specific config (max_file_count, expand_large) loads but doesn't automatically propagate to DirectoryIntelligenceTool unless explicitly coded.
Configuration Guide → | FastMCP Integration →
3. Sandbox Execution Engine
File: src/execute_code.py
Secure Python execution with Daytona primary backend and Docker fallback.
Key Features:
Backend Fallback - Daytona-first, automatic Docker fallback
Persistent Filesystem - Files written to workspace persist across executions
Daytona/Docker Parity - Identical pip-install failure semantics across backends
Sequential Execution - Thread-safe with deterministic order
Quickstart:
Workspace Semantics:
Filesystem persists: files remain accessible across executions
Interpreter resets: each execution starts fresh (no variable persistence)
Best practice: Always re-import modules in each execution
Sandbox Documentation → | Backend Selection →
4. Development Environment (.devcontainer/devcontainer.json)
Pre-configured development environment with:
Python 3.11 with required dependencies
Docker-in-Docker support
VS Code extensions for Python development
Port forwarding for FastMCP server
Reproducible environment setup
5. Test Suite (test/test.py)
Comprehensive test suite covering:
Basic script execution and output capture
Persistent workspace behavior
Error handling and edge cases
Sequential execution verification
Dependency installation testing
Installation
Prerequisites
Python 3.11+
Either Daytona SDK or Docker SDK (for sandbox execution)
Git (for directory analysis)
Setup Steps
Clone the repository:
Install dependencies:
Optional: Install Daytona SDK for primary sandbox backend:
Optional: Install Docker SDK for fallback sandbox backend:
Usage
Running the FastMCP Server
The server will start and print:
Using the Directory Intelligence Tool
As a Python module:
Command line usage:
Using the Sandbox Execution Engine
Development Environment
Using VS Code DevContainer:
Open project in VS Code
Install DevContainer extension
Click "Reopen in Container" when prompted
Environment will be set up automatically
Manual development setup:
End-to-End Example
Here's a complete example combining both tools:
Testing
Run the test suite:
Troubleshooting
Common Issues
"No sandbox backend available"
Install Daytona SDK:
pip install daytona-sdkOr install Docker SDK:
pip install dockerEnsure Docker daemon is running
"FastMCP server won't start"
Check if port 8000 is already in use
Verify all dependencies are installed
Check FastMCP version compatibility
"Directory analysis fails"
Ensure you have read permissions for the target directory
Check that the path exists and is accessible
Verify .gitignore file format if present
"Tests fail with import errors"
Ensure PYTHONPATH includes the src directory
Check that all dependencies are installed
Verify you're running tests from the project root
Debug Mode
Enable debug logging:
Project Structure
Contributing
Fork the repository
Create a feature branch
Make your changes
Run the test suite
Submit a pull request
License
This project is part of the Directory Intelligence Tool suite.