- Firecracker VM Management: Create, manage, and delete lightweight Firecracker VMs
- Secure SSH Integration: Execute commands and manage files through SSH connections
- REST API: Full-featured Express.js API for VM and execution operations
- Database Integration: PostgreSQL with Prisma ORM for data persistence
- Redis Caching: Redis for session management and VM state tracking
- Network Management: Automatic TAP interface and bridge network setup
- User Management: Multi-user support with project isolation
- Express Server (
src/index.ts): Main entry point running on port 8080 - Routes (
src/routes/):/firecracker/*- VM management endpoints/firecracker/exec/*- Command execution endpoints
- VM Creation (
firecracker.create.ts): Provisions new Firecracker VMs - VM Deletion (
firecracker.delete.ts): Cleanup and resource deallocation - Network Setup (
firecracker.network.ts): TAP interfaces and bridge networking - VM Configuration (
firecracker.config.ts): VM resource configuration - Boot Management (
firecracker.boot.ts): VM startup procedures
- VM Controller (
createVM.controller.ts):POST /firecracker/create- Create new VMPOST /firecracker/delete- Delete existing VMPOST /firecracker/get-host- Get VM host URL
- Execution Controller (
exec.controller.ts):POST /firecracker/exec/run- Execute commands in VMPOST /firecracker/exec/create-dir- Create directoriesPOST /firecracker/exec/write- Write files to VM
- SSH Service (
ssh/): Secure command execution and file operations - Redis Service (
redis/): Caching and session management
- Prisma ORM: Database abstraction and type safety
- Models: User, Project, VirtualMachine, Session management
User: User management with API keys
βββ Projects: User's coding projects
βββ Sessions: Authentication sessions
βββ VirtualMachines: VM instances with network config
VirtualMachine:
- VM IP, MAC address, socket path
- Resource specs (vCPU, memory)
- Status tracking and user association- Bridge Network:
br0(172.16.0.1/24) - VM IP Range: 172.16.0.2 - 172.16.0.20
- Host Port Mapping: Each VM IP maps to specific host ports (8000-8018)
- TAP Interfaces: Dynamic TAP creation per VM
- Internet Access: NAT forwarding through host interface
- Node.js 18+ with TypeScript support
- PostgreSQL database
- Redis server
- Firecracker binary and kernel images
- Ubuntu rootfs image for VMs
- Sudo access for network configuration
- Clone and install dependencies:
git clone <repository>
cd own-e2b
npm install- Set up environment variables:
# Database
DATABASE_URL="postgresql://username:password@localhost:5432/e2b"
DIRECT_URL="postgresql://username:password@localhost:5432/e2b"
# Add other required environment variables- Database setup:
npx prisma generate
npx prisma db push- Prepare VM images (update paths in controller):
# Download or build kernel and rootfs
# Update paths in src/controller/createVM.controller.ts:
# - kernelImage: "/path/to/vmlinux"
# - rootfsPath: "/path/to/ubuntu.ext4"- Start the server:
npm run devPOST /firecracker/create
{
"userId": "user-id-here"
}Returns VM details including IP, MAC, and connection info.
POST /firecracker/delete
{
"id": "vm-id",
"userId": "user-id"
}POST /firecracker/get-host
{
"userId": "user-id",
"ip": "172.16.0.2",
"id": "vm-id"
}POST /firecracker/exec/run
{
"id": "vm-id",
"userId": "user-id",
"command": "ls -la",
"projectId": "project-id",
"path": "/optional/working/directory"
}POST /firecracker/exec/create-dir
{
"id": "vm-id",
"userId": "user-id",
"path": "/path/to/create"
}POST /firecracker/exec/write
{
"id": "vm-id",
"userId": "user-id",
"projectId": "project-id",
"path": "filename.txt",
"content": "file content here"
}- Memory: 512MB
- vCPUs: 1
- Network: Bridge mode with internet access
- SSH: Automatic connection with retry logic
src/
βββ controller/ # API request handlers
βββ firecracker/ # VM management core
βββ lib/ # Utilities and database
β βββ generated/ # Prisma generated client
β βββ prisma.ts # Database connection
βββ prisma/ # Database schema
βββ routes/ # Express route definitions
βββ services/ # External service integrations
βββ redis/ # Caching layer
βββ ssh/ # Secure command execution
- Isolated VMs: Each user gets isolated Firecracker VMs
- SSH Key Authentication: Secure command execution
- Network Isolation: VMs run in isolated network namespaces
- Resource Limits: Configurable CPU and memory constraints
- User Isolation: Database-level user and project separation
- Runtime: Node.js with TypeScript
- Framework: Express.js
- Database: PostgreSQL with Prisma ORM
- Caching: Redis
- Virtualization: Firecracker VMM
- SSH: ssh2 library for secure connections
- Controllers: Handle HTTP requests and responses
- Services: Reusable business logic components
- Firecracker Module: VM lifecycle management
- Types: TypeScript type definitions
- VM Pool Management: Redis tracks allocated IPs and resources
- Connection Pooling: SSH connections are pooled and reused
- Resource Cleanup: Automatic cleanup on VM deletion
- Network Limits: Supports up to 19 concurrent VMs (172.16.0.2-20)
- Update hardcoded VM image paths in controllers
- Configure proper logging and monitoring
- Set up proper authentication/authorization
- Review network security and firewall rules
- Monitor VM resource usage and cleanup orphaned VMs