Skip to content

[v2.6+] Implement provider auto-selection heuristics #36

@frankbria

Description

@frankbria

Overview

Automatically select the best sandbox provider based on task characteristics when no explicit provider is specified.

Selection Criteria

Task Duration

  • < 5 minutes: Native/Docker (free, instant)
  • 5-30 minutes: Native/Docker or E2B
  • 30 minutes: E2B (more reliable for long tasks)

Resource Requirements

  • Low CPU/memory: Native
  • Medium: Docker
  • High/GPU: E2B (dedicated VM)

Network Requirements

  • No external access: Native (most secure)
  • External APIs: Docker or E2B
  • Full network: E2B

User Preference

  • Cost-conscious: Native > Docker > E2B
  • Speed-focused: E2B (parallel VM)
  • Security-focused: Native (OS-level isolation)

Implementation

// src/e2b/providers/auto-select.ts

export interface TaskHints {
  estimatedDuration?: number;  // minutes
  requiresNetwork?: boolean;
  requiresGpu?: boolean;
  resourceIntensity?: 'low' | 'medium' | 'high';
  costSensitive?: boolean;
}

export function selectProvider(
  hints: TaskHints,
  available: string[]
): string {
  // Quick tasks → prefer free providers
  if (hints.estimatedDuration && hints.estimatedDuration < 5) {
    if (available.includes('native')) return 'native';
    if (available.includes('docker')) return 'docker';
  }
  
  // Long tasks → prefer E2B for reliability
  if (hints.estimatedDuration && hints.estimatedDuration > 30) {
    if (available.includes('e2b')) return 'e2b';
  }
  
  // Cost-sensitive → prefer free options
  if (hints.costSensitive) {
    if (available.includes('native')) return 'native';
    if (available.includes('docker')) return 'docker';
  }
  
  // Default: use E2B if available
  if (available.includes('e2b')) return 'e2b';
  
  // Fallback to first available
  return available[0] || 'e2b';
}

CLI Integration

# Let parallel-cc decide
parallel-cc sandbox-run --repo . --prompt "Quick fix" --auto-provider

# Provide hints
parallel-cc sandbox-run --repo . --prompt "Long task" \
  --estimated-duration 45 \
  --cost-sensitive

Files to Create

  • `src/e2b/providers/auto-select.ts`
  • `tests/e2b/auto-select.test.ts`

Acceptance Criteria

  • Auto-selection chooses appropriate provider
  • User hints influence selection
  • Fallback chain works when preferred unavailable
  • Clear logging of selection reasoning
  • Unit tests cover various scenarios

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    component-e2bE2B sandbox integrationenhancementNew feature or requestphase-2-multi-providerPhase 2: Multi-provider sandbox architecture (v2.5)priority-lowLow priority - when convenient

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions