Skip to content

[v2.5+] Implement DockerProvider #34

@frankbria

Description

@frankbria

Overview

Implement a Docker-based sandbox provider for cross-platform sandboxing without cloud costs.

Implementation

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

export class DockerProvider implements SandboxProvider {
  readonly name = 'docker';
  readonly version = '1.0.0';
  
  private defaultImage = 'claude-code:latest';
  
  static async isAvailable(): Promise<boolean> {
    try {
      execSync('docker info', { stdio: 'pipe' });
      return true;
    } catch {
      return false;
    }
  }
  
  async create(config: SandboxConfig): Promise<SandboxInstance> {
    // docker run -d --name <name> -v <workdir>:/workspace <image>
    const containerId = await this.startContainer(config);
    return {
      id: containerId,
      provider: 'docker',
      status: SandboxStatus.RUNNING,
      createdAt: new Date()
    };
  }
  
  async execute(instanceId: string, command: string): AsyncGenerator<string> {
    // docker exec -t <instanceId> <command>
    // Stream output line by line
  }
  
  async destroy(instanceId: string): Promise<void> {
    // docker stop <instanceId> && docker rm <instanceId>
  }
}

Docker Image

Create official claude-code Docker image:

# docker/Dockerfile
FROM node:20-slim

# Install Claude CLI
RUN npm install -g @anthropic-ai/claude-code

# Install common development tools
RUN apt-get update && apt-get install -y \
  git \
  curl \
  python3 \
  python3-pip

WORKDIR /workspace

# Entry point that keeps container running
ENTRYPOINT ["tail", "-f", "/dev/null"]

Configuration

# Use custom image
parallel-cc sandbox-run --provider docker --docker-image my-image:tag

# Resource limits
parallel-cc sandbox-run --provider docker --memory 4g --cpus 2

Platform Support

  • macOS (Docker Desktop)
  • Linux (Docker Engine)
  • Windows (Docker Desktop with WSL2)

Files to Create

  • src/e2b/providers/docker-provider.ts
  • docker/Dockerfile
  • docker/docker-compose.yml (for easy local testing)
  • tests/e2b/docker-provider.test.ts

Acceptance Criteria

  • Container creation works
  • File mounting works correctly
  • Command execution with output streaming
  • Proper cleanup (stop and remove)
  • Works on macOS, Linux, and Windows
  • Integration tests pass

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-mediumMedium priority - next milestonetype-featureNew feature implementation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions