Skip to content

[v1.5] Refactor E2B code into E2BProvider classย #31

@frankbria

Description

@frankbria

Overview

Extract existing E2B logic from sandbox-manager.ts and file-sync.ts into a new E2BProvider class that implements the SandboxProvider interface.

Scope

Move to E2BProvider

  • Sandbox creation logic
  • File upload/download operations
  • Execution handling
  • Health monitoring
  • Reconnection logic

Keep in SandboxManager

  • Provider registry
  • Provider selection
  • Session tracking
  • High-level orchestration

Implementation

// src/e2b/providers/e2b-provider.ts

import { SandboxProvider, SandboxConfig, SandboxInstance } from './types.js';
import { Sandbox } from 'e2b';

export class E2BProvider implements SandboxProvider {
  readonly name = 'e2b';
  readonly version = '1.0.0';
  
  private sandboxes: Map<string, Sandbox> = new Map();
  
  async create(config: SandboxConfig): Promise<SandboxInstance> {
    // Move logic from SandboxManager.createSandbox()
  }
  
  async destroy(instanceId: string): Promise<void> {
    // Move logic from SandboxManager.terminateSandbox()
  }
  
  // ... implement remaining interface methods
}

Migration Steps

  1. Create E2BProvider class skeleton
  2. Move createSandbox logic
  3. Move terminateSandbox logic
  4. Move file upload/download
  5. Update SandboxManager to use E2BProvider
  6. Verify all tests pass
  7. Remove dead code from old locations

Files to Modify

  • src/e2b/providers/e2b-provider.ts - New provider class
  • src/e2b/sandbox-manager.ts - Refactor to use provider
  • src/e2b/file-sync.ts - May be split into provider

Acceptance Criteria

  • E2BProvider implements full SandboxProvider interface
  • All existing tests pass
  • No behavior changes for CLI users
  • Code is cleaner and more modular
  • Good test coverage for E2BProvider

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    component-e2bE2B sandbox integrationenhancementNew feature or requestphase-2-multi-providerPhase 2: Multi-provider sandbox architecture (v1.5)priority-highHigh priority - address soontype-refactorCode refactoring or restructuring

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions