My AI can read and write on my computer. It has access to:
- 500+ blog posts (past content)
- 200+ draft files (work in progress)
- Research notes (Obsidian vault)
- Images folder (10,000+ files)
- Analytics exports (CSV files)
Safely and securely.
Why File Access Matters
Without it:
- You manually copy/paste files
- AI can't understand context
- Work in isolation (no past knowledge)
With file access:
- Auto-reads all content
- Learns your writing style
- Uses research notes for context
- Analyzes patterns across everything
- Directly saves outputs
Example Workflow:
# Without file access (manual)
agent.run("Analyze my writing voice")
time: 20 minutes
# With file access (automated)
agent.analyze_writing_voice("/blog/*.mdx")
time: 2 minutes
Security First: Risks and Prevention
Risks:
- Delete important files
- Overwrite documents
- Read sensitive data
- Upload to servers
- Modify system files
Prevention:
- Sandboxing - Restrict access
- Read-only by default - Allow write only when needed
- Approval gates - Ask before writing/deleting
- Logging - Track every operation
- Exclude sensitive data
Method 1: Python File Access
Best for local agents.
import os
from pathlib import Path
class FileAccess:
def __init__(self, dirs):
self.allowed_dirs = [Path(d).resolve() for d in dirs]
def is_safe_path(self, path):
return any(path.resolve().is_relative_to(d) for d in self.allowed_dirs)
def read_file(self, file_path):
if not self.is_safe_path(file_path):
return "Access denied"
try:
with open(file_path, 'r') as f:
content = f.read()
return content
except Exception as e:
return str(e)
def write_file(self, file_path, content, require_approval=True):
if not self.is_safe_path(file_path):
return "Access denied"
approval = input(f"Write to {file_path}? (y/n): ")
if approval.lower() != 'y':
return "User denied"
try:
with open(file_path, 'w') as f:
f.write(content)
return "Success"
except Exception as e:
return str(e)
# Usage
allowed_dirs = ["/home/user/blog", "/home/user/drafts"]
file_access = FileAccess(allowed_dirs)
result = file_access.read_file("/home/user/blog/my-post.md")
print(result)
Method 2: LangChain File Tools
Best for using LangChain.
from langchain import initialize_agent, ChatOpenAI
from langchain.tools.file_management import FileManagementToolkit
file_management = FileManagement(
root_dir="/home/user/blog",
selected_tools=['read_file', 'write_file', 'list_directory']
)
toolkit = FileManagementToolkit(file_management=file_management)
agent = initialize_agent(toolkits=[toolkit], llm=ChatOpenAI(model="gpt-4"), agent="openai-functions")
result = agent.run("Read all markdown files and summarize the main topics")
My Complete Setup
ALLOWED_DIRECTORIES = {
'blog_posts': '/home/billk/blog/content/posts',
'drafts': '/home/billk/blog/drafts',
'research': '/home/billk/Documents/Research',
'images': '/home/billk/blog/images',
'analytics': '/home/billk/Documents/Analytics'
}
RESTRICTED_DIRECTORIES = [
'/home/billk/.ssh', # SSH keys
'/home/billk/.aws', # AWS credentials
'/home/billk/.env', # Environment variables
'/home/billk/passwords' # Password manager
]
def train_voice_profile():
posts = file_access.list_files(ALLOWED_DIRECTORIES['blog_posts'], pattern='*.md')
all_content = [file_access.read_file(post)['content'] for post in posts]
voice_profile = analyze_writing_voice('\n\n'.join(all_content))
file_access.write_file('/home/billk/agent-data/voice-profile.json', json.dumps(voice_profile), require_approval=False)
def research_topic(topic):
blog_matches = search_files(ALLOWED_DIRECTORIES['blog_posts'], query=topic)
note_matches = search_files(ALLOWED_DIRECTORIES['research'], query=topic)
research = {
'blog_posts': blog_matches,
'notes': note_matches
}
return research
def manage_drafts():
drafts = file_access.list_files(ALLOWED_DIRECTORIES['drafts'], pattern='*.md')
for draft_path in drafts:
draft_content = file_access.read_file(draft_path)['content']
analysis = analyze_draft_quality(draft_content)
if analysis['quality_score'] >= 80:
print(f"✅ {draft_path} ready to publish")
elif analysis['quality_score'] >= 50:
print(f"⚠️ {draft_path} needs: {analysis['improvements']}")
else:
print(f"🗑️ {draft_path} archiving")
Security Best Practices
- Least Privilege - Give minimum needed access
- Approval Gates - Ask before critical operations
- Backup Before Write - Create backups first
Tools & Libraries
- pathlib (Python standard library)
- LangChain File Tools
Cost: Free/Open Source
Real Results
Before file access:
- 30+ minutes per task
- No context from past work
After:
- Auto-reads all content
- Full context of everything
- Time: 2 minutes
Do it now. Check out my real AI tools at axon.nepa-ai.com.
