Filesystem Tools
Comprehensive filesystem operations across different environments with support for local, in-memory, and sandboxed execution.Overview
AG-Kit provides filesystem tools that work across three different backends:- Local File Operator: Direct filesystem access (maximum performance)
- In-Memory File Operator: Virtual filesystem in memory (testing/isolation)
- Sandbox File Operator: Secure operations in E2B containers (production safe)
Available Tools
Individual Tools
- ReadTool - Read file contents with encoding support
- WriteTool - Write content to files with directory creation
- EditTool - Make targeted edits to existing files
- MultiEditTool - Batch edit multiple files in sequence
- GlobTool - Find files using glob patterns
- GrepTool - Search file contents with regex patterns
- LsTool - List directory contents with detailed information
Comprehensive Tool
- StrReplaceEditor - Advanced multi-operation file editor for AI coding workflows
Quick Comparison
| Feature | Local | In-Memory | Sandbox |
|---|---|---|---|
| Performance | ✅ Maximum | ✅ High | ⚠️ Network overhead |
| Security | ⚠️ Full access | ✅ Isolated | ✅ Sandboxed |
| Persistence | ✅ Permanent | ❌ Temporary | ✅ Session-based |
| Testing | ⚠️ Side effects | ✅ Perfect | ⚠️ Complex setup |
Setup
Local File Operator
In-Memory File Operator
Sandbox File Operator
Environment Setup: Create a.envfile in your project root:Get your API key from E2B Dashboard.
Individual Tools Usage
ReadTool
WriteTool
EditTool
MultiEditTool
GlobTool
GrepTool
LsTool
StrReplaceEditor
Advanced file editing tool designed for AI coding workflows:API Reference
Common Interfaces
Tool Factory Functions
Advanced Usage
Multi-Backend Workflow
Batch Operations
Error Handling
Security Features
Path Validation
All tools automatically validate paths to prevent directory traversal attacks:Production Recommendations
- Use Sandbox File Operator for untrusted code
- Use In-Memory File Operator for testing
- Use Local File Operator only for trusted environments
Examples
Development Workflow
File Refactoring Workflow
File Processing Pipeline
Performance Optimization
Parallel Operations
Best Practices
- Validate paths: Always use relative paths within workspace
- Handle errors: Check
successanderror_typefields - Use appropriate backend: Match environment needs
- Batch operations: Use
multieditfor multiple changes - Clean up: Remove temporary files
- Log operations: Track file changes
Troubleshooting
File Not Found
Path Security Violation
Examples Repository
Find complete working examples at:- fs_tools.py - Basic file system operations
- fs_comprehensive.py - Comprehensive FS tools examples
- langchain_adapter.py - LangChain integration
- llamaindex_adapter.py - LlamaIndex integration