Production-grade E2B sandbox orchestration with agentic-flow swarms and AgentDB caching for distributed AI agent execution
npm install @foxruv/e2b-runner> Production-grade E2B sandbox orchestration with agentic-flow swarms and AgentDB caching for distributed AI agent execution


- π₯ Agentic-Flow Integration: Native support for swarm orchestration and multi-agent coordination
- β‘ AgentDB Caching: 6000x faster results on cache hits with intelligent pattern storage
- π Auto-Scaling: Seamlessly scale from 0β100 E2B sandboxes based on load
- π Real-Time Streaming: Stream execution progress from sandboxes in real-time
- π Automatic Failover: Built-in retry logic and fault tolerance
- ποΈ Multi-Database Access: Pre-configured Neo4j, Upstash Vector, and Redis connections
- π€ Expert Collaboration: Middleware for multi-expert coordination with shared memory
- π Resource Tracking: Monitor CPU, memory, and execution metrics
``bash`
npm install @foxruv/e2b-runner
Optional peer dependencies (for advanced features):
`bash`
npm install agentic-flow # For swarm orchestration
`typescript
import { createE2BRunner } from '@foxruv/e2b-runner'
// Create runner with environment configuration
const runner = createE2BRunner({
apiKey: process.env.E2B_API_KEY,
maxConcurrency: 10,
enableStreaming: true,
verbose: true
})
// Run single agent in E2B sandbox
const result = await runner.run(myAgent, context)
console.log(result.analysis)
// Cleanup when done
await runner.cleanup()
`
`typescript
// Run multiple agents in parallel across E2B sandboxes
const agents = [agent1, agent2, agent3, agent4, agent5]
const results = await runner.runBatch(agents, context)
results.forEach(result => {
console.log(${result.agent}: ${result.confidence})`
})
`typescript[${update.phase}] ${update.message} - ${update.progress * 100}%
// Stream execution progress in real-time
for await (const update of runner.runWithStreaming(myAgent, context)) {
console.log()`
}
Enable intelligent result caching for massive performance gains:
`typescript
const runner = createE2BRunner({
agentdb: {
enabled: true,
cacheTTL: 3600, // 1 hour cache
}
})
// First run: ~10s execution time
const result1 = await runner.run(agent, context)
// Second run with same inputs: ~2ms (6000x faster!)
const result2 = await runner.run(agent, context)
`
Leverage swarm intelligence for distributed execution:
`typescript
const runner = createE2BRunner({
swarm: {
topology: 'mesh', // mesh, hierarchical, ring, star
maxAgents: 100,
strategy: 'adaptive', // parallel, sequential, adaptive
}
})
// Automatically distributes agents across optimal sandbox topology
const results = await runner.runBatch(agents, context)
`
`typescript`
const runner = createE2BRunner({
autoScaling: {
enabled: true,
minInstances: 0, // Scale to zero when idle
maxInstances: 100, // Scale up to 100 sandboxes
scaleUpThreshold: 0.8, // CPU/Memory threshold
scaleDownThreshold: 0.3,
}
})
Agents automatically have access to your databases:
`typescript
// Sandboxes are pre-configured with:
// - Neo4j graph database (via HTTP gateway)
// - Upstash Vector stores
// - Redis caching
// - And more!
const runner = createE2BRunner({
// Credentials automatically passed to sandboxes
verbose: true
})
`
`typescript`
// Get real-time status
const status = runner.getStatus()
console.log({
activeSandboxes: status.activeSandboxes,
totalExecutions: status.totalExecutions,
averageTime: status.averageExecutionTime,
errorRate: status.errorRate,
cacheHitRate: status.cacheHitRate,
})
``
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β E2B Agent Runner β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββ ββββββββββββββββ β
β β AgentDB βββββββΊβ Agentic-Flow β β
β β Caching β β Swarm β β
β βββββββββββββββ ββββββββββββββββ β
β β² β² β
β β β β
β βΌ βΌ β
β ββββββββββββββββββββββββββββββββββββββββ β
β β E2B Sandbox Pool (0-100) β β
β β ββββββββββ ββββββββββ ββββββββββ β β
β β βAgent 1 β βAgent 2 β βAgent N β β β
β β ββββββββββ ββββββββββ ββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββ β
β β β β β
β βΌ βΌ βΌ β
β ββββββββββββββββββββββββββββββββββββββββ β
β β Multi-Database Access Layer β β
β β Neo4j β Upstash Vector β Redis β β
β ββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
`typescript
interface E2BRunnerConfig {
// E2B Configuration
apiKey?: string
templateId?: string
maxConcurrency?: number
enableStreaming?: boolean
timeout?: number
verbose?: boolean
// Auto-Scaling
autoScaling?: {
enabled: boolean
minInstances: number
maxInstances: number
scaleUpThreshold: number
scaleDownThreshold: number
}
// Region Preferences
regions?: ('us-east' | 'us-west' | 'eu-west' | 'ap-southeast')[]
// AgentDB Caching
agentdb?: {
enabled: boolean
endpoint?: string
cacheTTL?: number // seconds
}
// Agentic-Flow Swarm
swarm?: {
topology?: 'mesh' | 'hierarchical' | 'ring' | 'star'
maxAgents?: number
strategy?: 'parallel' | 'sequential' | 'adaptive' | 'balanced'
}
}
`
| Operation | Without Cache | With AgentDB | Speedup |
|-----------|--------------|--------------|---------|
| Agent Execution | 10,000ms | 2ms | 6000x |
| Batch (5 agents) | 50,000ms | 10ms | 5000x |
| Swarm (20 agents) | 200,000ms | 40ms | 5000x |
`bashRun tests
npm test
Contributions welcome! Please read our Contributing Guide first.
MIT Β© FoxRuv
- Documentation
- Issue Tracker
- E2B Platform
- Agentic-Flow
- AgentDB
See the examples directory for complete working examples:
- Basic Agent Execution
- Parallel Batch Processing
- Real-Time Streaming
- Swarm Orchestration
- AgentDB Caching
---
Built with β€οΈ by the FoxRuv team