TinyFS is a secure filesystem interface that enables large language models (LLMs) to safely interact with the filesystem. It provides robust security controls, path validation, and user confirmation mechanisms to prevent potentially dangerous operations.
- Overview
- Installation
- Usage
- Core Concepts
- Security Considerations
- API Reference
- Implementation Notes
- Future Roadmap
TinyFS provides a secure way for language models to perform filesystem operations while maintaining strong security boundaries. It includes:
- Secure File Operations: Read, write, copy, move, and delete files within a designated workspace
- Directory Management: List, create, and navigate directory structures
- Path Validation: Prevents directory traversal attacks and restricts operations to the workspace
- User Confirmation: Interactive confirmation for potentially dangerous operations
- Detailed Logging: Comprehensive logging for audit trails
- Sandboxing: (Coming in Phase 2) Docker-based sandboxing for command execution
TinyFS is integrated into GhostForge. To use it:
# Clone the GhostForge repository
git clone https://github.com/yourusername/ghostforge.git
cd ghostforge
# Install dependencies
pip install -r requirements.txtfrom ghostforge.tinyfs import TinyFSClient
# Initialize with a workspace directory
client = TinyFSClient(workspace_dir="/path/to/workspace")
# Read a file
content = client.read_file("example.txt")
print(content)
# Write to a file (requires confirmation unless auto_confirm=True)
client.write_file("output.txt", "Hello, world!")
# List directory contents
files = client.list_directory(".")
for file_info in files:
print(f"{file_info.name}: {'Directory' if file_info.is_directory else 'File'}")
# Create a directory
client.create_directory("new_directory")
# Copy a file
client.copy_file("source.txt", "destination.txt")
# Delete a file
client.delete_file("to_delete.txt")# Read a file
python -m ghostforge.tinyfs.cli read example.txt
# Write to a file
python -m ghostforge.tinyfs.cli write output.txt "Hello, world!"
# List directory contents
python -m ghostforge.tinyfs.cli list
# Create a directory
python -m ghostforge.tinyfs.cli mkdir new_directory
# Set a specific workspace and enable auto-confirmation
python -m ghostforge.tinyfs.cli --workspace /path/to/project --auto-confirm write config.json '{"version": "1.0"}'# Start the GhostForge shell
python -m ghostforge.shell
# Inside the shell:
ghostforge> fs help
# Shows help for all fs commands
ghostforge> fs read example.txt
# Reads and displays the content of example.txt
ghostforge> fs write output.txt "Hello, world!"
# Writes text to output.txt
ghostforge> fs list
# Lists the contents of the current directory
TinyFS operates within a designated "workspace" directory. All operations are restricted to this workspace to prevent unauthorized access to the broader filesystem. The workspace is specified when creating a TinyFSClient instance:
client = TinyFSClient(workspace_dir="/path/to/workspace")All path operations are validated to ensure they remain within the workspace boundary. This prevents directory traversal attacks and unauthorized access to files outside the workspace.
# This succeeds if example.txt is in the workspace
client.read_file("example.txt")
# This fails with a SecurityError
client.read_file("/etc/passwd")
# This fails with a SecurityError
client.read_file("../outside_workspace.txt")Potentially dangerous operations (write, delete, etc.) require user confirmation before execution. This prevents unintended or malicious changes to the filesystem.
# This will prompt for confirmation unless auto_confirm=True
client.write_file("important_file.txt", "New content")
# To bypass confirmation
client = TinyFSClient(workspace_dir="/path/to/workspace", auto_confirm=True)All operations are logged with detailed information for audit purposes. This includes the action type, timestamp, path, and success/failure status.
# Configure logging level
client = TinyFSClient(workspace_dir="/path/to/workspace", log_level=logging.DEBUG)TinyFS implements several security measures:
- Workspace Isolation: All operations are contained within a designated workspace directory.
- Path Validation: All paths are validated to prevent directory traversal and access outside the workspace.
- User Confirmation: Potentially dangerous operations require explicit confirmation.
- Parent Directory Creation: When writing to files, parent directories are automatically created but cannot escape the workspace boundary.
- Error Handling: Proper error handling prevents information leakage and maintains security boundaries.
The main client for interacting with the filesystem.
def __init__(self, workspace_dir: Union[str, Path], auto_confirm: bool = False, log_level: int = logging.INFO, history_size: int = 100)workspace_dir: Root directory for all operationsauto_confirm: Whether to auto-confirm operationslog_level: Logging verbosity levelhistory_size: Maximum number of actions to keep in history
def read_file(self, path: Union[str, Path]) -> str
def write_file(self, path: Union[str, Path], content: str, confirm: bool = True) -> bool
def delete_file(self, path: Union[str, Path], confirm: bool = True) -> bool
def copy_file(self, source: Union[str, Path], destination: Union[str, Path], confirm: bool = True) -> bool
def move_file(self, source: Union[str, Path], destination: Union[str, Path], confirm: bool = True) -> booldef list_directory(self, path: Union[str, Path] = ".") -> List[FileInfo]
def create_directory(self, path: Union[str, Path], confirm: bool = True) -> bool
def directory_exists(self, path: Union[str, Path]) -> booldef file_exists(self, path: Union[str, Path]) -> bool
def get_file_info(self, path: Union[str, Path]) -> Optional[FileInfo]
def get_history(self) -> List[ActionRecord]TinyFS is implemented in pure Python with a focus on security and simplicity. Key design decisions include:
- Path Validation: All paths are validated using
Path.resolve()to get canonical paths and prevent path traversal attacks. - Workspace Boundary: The workspace boundary is enforced by checking if the resolved path starts with the resolved workspace path.
- Parent Directory Creation: When writing to a file, parent directories are automatically created but cannot escape the workspace boundary.
- Error Handling: Detailed exception hierarchy for different types of errors (security, validation, cancellation).
- Confirmation System: Interactive confirmation system for potentially dangerous operations with auto-confirm option for non-interactive use.
TinyFS is being developed in phases:
- ✅ File read/write operations with path validation
- ✅ Directory listing and navigation
- ✅ Basic logging infrastructure
- 🔄 Docker-based sandboxing
- 🔄 Command execution with security controls
- 🔄 User confirmation system enhancements
- 🔜 Git repository operations
- 🔜 Dependency management
- 🔜 Diffing and patching support
- 🔜 Custom commands for GhostForge shell
- 🔜 LLM prompting for tool usage
- 🔜 GUI confirmation dialogs
- 🔜 Comprehensive testing and security review
- 🔜 Documentation and examples
- 🔜 Performance optimization