A sandboxed coding agent that automatically creates pull requests based on natural language prompts. Built with FastAPI, Modal, and Claude AI.
- Streaming API: Real-time updates via Server-Sent Events
- AI-Powered Code Generation: Uses Claude to analyze codebases and generate intelligent changes
- Secure Sandboxing: Runs in isolated Modal environments
- Automatic PR Creation: Creates GitHub pull requests with detailed descriptions
- Multi-language Support: Works with Python, JavaScript, TypeScript, Go, Rust, and more
- Real-time Observability: Comprehensive logging and streaming updates
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ FastAPI App โโโโโถโ Coding Agent โโโโโถโ Claude AI โ
โ (Streaming) โ โ (Analysis) โ โ (Code Gen) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ โ
โผ โผ โผ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Git Service โ โ Modal Sandbox โ โ GitHub API โ
โ (Repo Ops) โ โ (Isolation) โ โ (PR Creation) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
- Python 3.8+
- GitHub Personal Access Token (with repo permissions)
- Anthropic API Key (for Claude)
- Modal account (for sandboxing)
-
Clone the repository
git clone <your-repo-url> cd tiny-backspace
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
# Create .env file cp .env.example .env # Edit .env with your credentials GITHUB_TOKEN=your_github_personal_access_token ANTHROPIC_API_KEY=your_anthropic_api_key
-
Set up Modal (optional for local development)
modal token new
-
Start the API server
python -m app.main
-
Test the API
python test_client.py
Main endpoint for coding agent requests.
Request:
{
"repoUrl": "https://github.com/username/repo",
"prompt": "Add input validation to all POST endpoints"
}Response (Server-Sent Events):
data: {"type": "Status", "message": "Starting Tiny Backspace coding agent..."}
data: {"type": "Tool", "action": "git_clone", "repo": "https://github.com/username/repo"}
data: {"type": "Analysis", "data": {"languages": ["Python"], "frameworks": ["FastAPI"]}}
data: {"type": "AI Message", "message": "Analyzing codebase structure..."}
data: {"type": "Tool", "action": "edit", "filepath": "app.py", "type": "edit"}
data: {"type": "Success", "pr_url": "https://github.com/username/repo/pull/123"}
Health check endpoint.
API information and status.
import asyncio
import aiohttp
import json
async def create_pr():
async with aiohttp.ClientSession() as session:
async with session.post(
"http://localhost:8000/code",
json={
"repoUrl": "https://github.com/example/simple-api",
"prompt": "Add error handling and logging to all endpoints"
}
) as response:
async for line in response.content:
if line.startswith(b'data: '):
data = json.loads(line[6:].decode())
print(f"{data['type']}: {data.get('data', {}).get('message', '')}")
asyncio.run(create_pr())| Variable | Description | Required |
|---|---|---|
GITHUB_TOKEN |
GitHub Personal Access Token | Yes |
ANTHROPIC_API_KEY |
Anthropic API Key for Claude | Yes |
MODAL_TOKEN_ID |
Modal token ID (for sandboxing) | No |
Your GitHub token needs the following permissions:
repo(Full control of private repositories)workflow(Update GitHub Action workflows)
I chose Claude 3 Sonnet as the coding agent for several reasons:
- Code Understanding: Claude excels at understanding codebases and generating contextually appropriate changes
- Multi-language Support: Handles Python, JavaScript, TypeScript, Go, Rust, and more
- Structured Output: Can generate JSON responses for structured implementation plans
- Safety: Built-in safety measures and ethical considerations
- Reliability: Consistent and high-quality code generation
- Codebase Analysis: Scans repository structure and identifies key files
- Implementation Planning: Generates detailed plan using Claude
- Code Generation: Creates specific file changes based on the plan
- Git Operations: Creates branch, commits changes, and pushes
- PR Creation: Automatically creates pull request with detailed description
- Modal Sandbox: All code execution happens in isolated Modal environments
- Temporary Directories: Repository cloning uses temporary directories that are cleaned up
- GitHub Token Scoping: Uses minimal required permissions
- Input Validation: Validates all inputs and repository URLs
- Error Handling: Comprehensive error handling and logging
The API provides real-time observability through:
- Streaming Events: Real-time updates on all operations
- Structured Logging: Comprehensive logging with different levels
- Progress Tracking: Detailed progress updates for each step
- Error Reporting: Clear error messages and debugging information
Run the test client to see the API in action:
python test_client.pyThis will:
- Test the health check endpoint
- Send a sample coding request
- Display real-time streaming updates
- Show the final PR creation result
python -m app.mainmodal deploy app.maindocker build -t tiny-backspace .
docker run -p 8000:8000 tiny-backspace๐งช Tiny Backspace API Test
==================================================
๐ฅ Health Check: healthy
๐ Starting Tiny Backspace Test
Repository: https://github.com/octocat/Hello-World
Prompt: Add a simple README section about contributing
--------------------------------------------------
๐ก Streaming response:
--------------------------------------------------
๐ Starting Tiny Backspace coding agent...
๐ง Cloning repository...
๐ Analyzing codebase with AI...
๐ Analysis: 1 languages, 0 frameworks, 3 files
๐ค AI: Implementation plan: Add contributing section to README...
๐ Plan: 1 files to modify
Add contributing section to README with guidelines...
โ๏ธ Editing: README.md
๐ Applying code changes...
๐ป Running: git checkout -b feature/backspace-1234
๐ป Running: git add .
๐ป Running: git commit -m 'Implement: Add a simple README section...'
๐ป Running: git push origin feature/backspace-1234
๐ Creating pull request...
๐ป Running: gh pr create --title 'Implement: Add a simple README...'
โ
Success! Successfully implemented 'Add a simple README section about contributing' with 1 changes
๐ PR URL: https://github.com/octocat/Hello-World/pull/123
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
MIT License - see LICENSE file for details.
-
GitHub Token Issues
- Ensure your token has the required permissions
- Check that the repository is accessible
-
Claude API Issues
- Verify your Anthropic API key is correct
- Check your API usage limits
-
Modal Sandbox Issues
- Ensure Modal is properly configured
- Check Modal account status and quotas
Enable debug logging:
export LOG_LEVEL=DEBUG
python -m app.main- Support for private repositories
- Integration with more AI models
- Advanced code review capabilities
- Support for more git platforms (GitLab, Bitbucket)
- Web UI for easier interaction
- Batch processing of multiple requests
- Advanced sandboxing with E2B or Daytona