Summary
Integrate Cloudflare as a first-class sandbox backend for Ralph. Cloudflare offers edge compute and container capabilities that can provide globally distributed, low-latency sandbox execution.
Problem Statement
Users may prefer Cloudflare over other sandbox options when they:
- Already use Cloudflare infrastructure
- Need edge/global distribution for latency reasons
- Want integration with Cloudflare's security features
- Prefer Cloudflare's pricing model
- Need to stay within Cloudflare's ecosystem for compliance
Cloudflare Compute Options
Cloudflare Containers (Primary Target)
- Container-based execution
- Longer-running workloads than Workers
- Full Linux environment
- Suitable for Ralph's autonomous execution
Cloudflare Workers (Limited Applicability)
- V8 isolate-based serverless
- Short execution limits (may be too restrictive)
- Could be used for lightweight tasks
Workers for Platforms
- Multi-tenant execution
- Could enable "Ralph as a Service" scenarios
Proposed CLI Interface
# Basic Cloudflare sandbox execution
ralph --sandbox cloudflare
# Specify Cloudflare product
ralph --sandbox cloudflare --cf-product containers
ralph --sandbox cloudflare --cf-product workers # Limited use cases
# Account configuration
ralph --sandbox cloudflare --cf-account-id "abc123"
ralph --sandbox cloudflare --cf-api-token "$CF_API_TOKEN"
# Region/location preferences
ralph --sandbox cloudflare --cf-region "us-east"
ralph --sandbox cloudflare --cf-colo "EWR" # Specific datacenter
# Resource configuration
ralph --sandbox cloudflare --memory 2g
ralph --sandbox cloudflare --timeout 3600
# Networking
ralph --sandbox cloudflare --cf-network "my-network" # Cloudflare network
Key Design Questions
-
Which Cloudflare Product?
- Containers most likely for full Ralph execution
- Workers for specific lightweight tasks?
- How to handle product evolution (CF adds new compute options)?
-
Authentication
- API token management
- Account ID configuration
- Scoped tokens for security
-
Container Image
- Use Ralph's official Docker image?
- Push to Cloudflare's registry?
- Or pull from Docker Hub/GHCR?
-
Networking
- Cloudflare's network model
- Access to Claude API from edge
- Tunnels for accessing user's services?
-
Persistence
- Cloudflare containers are ephemeral
- R2 for artifact storage?
- Durable Objects for state?
-
Cost Model
- Cloudflare has different pricing than E2B
- CPU-time based? Request-based?
- Budget controls needed
-
Edge Distribution
- Run near user for latency?
- Run near Claude API for API latency?
- Let Cloudflare decide?
Cloudflare API Overview
# Conceptual - actual API may differ
# Cloudflare Containers API
curl -X POST "https://api.cloudflare.com/client/v4/accounts/{account_id}/containers" \
-H "Authorization: Bearer $CF_API_TOKEN" \
-d '{"image": "ralph:latest", "resources": {"memory": "2g"}}'
# Get container status
curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/containers/{id}"
# Stream logs
curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/containers/{id}/logs"
Implementation Approach
- Create
lib/sandbox/cloudflare.sh implementing sandbox interface
- Implement Cloudflare API client for containers
- Handle container image deployment
- Implement file sync (upload to container, download artifacts)
- Integrate with ralph-monitor for log streaming
- Add cost tracking integration
- Tests with mocked Cloudflare API
Cloudflare-Specific Considerations
- Edge-first: Cloudflare's model is edge compute
- Ephemeral: Containers don't persist by default
- Global: Can run in multiple locations
- Integrated Security: WAF, DDoS protection built-in
- R2 Storage: Natural artifact storage option
- Evolving Platform: Cloudflare compute is rapidly evolving
Acceptance Criteria
Dependencies
Related
Notes
Cloudflare's compute offerings are evolving rapidly. This issue should be reviewed against current Cloudflare capabilities when implementation begins. The Containers product specifically should be validated as GA and suitable for this use case.
Summary
Integrate Cloudflare as a first-class sandbox backend for Ralph. Cloudflare offers edge compute and container capabilities that can provide globally distributed, low-latency sandbox execution.
Problem Statement
Users may prefer Cloudflare over other sandbox options when they:
Cloudflare Compute Options
Cloudflare Containers (Primary Target)
Cloudflare Workers (Limited Applicability)
Workers for Platforms
Proposed CLI Interface
Key Design Questions
Which Cloudflare Product?
Authentication
Container Image
Networking
Persistence
Cost Model
Edge Distribution
Cloudflare API Overview
Implementation Approach
lib/sandbox/cloudflare.shimplementing sandbox interfaceCloudflare-Specific Considerations
Acceptance Criteria
--sandbox cloudflareflag launches Ralph in Cloudflare containerDependencies
Related
Notes
Cloudflare's compute offerings are evolving rapidly. This issue should be reviewed against current Cloudflare capabilities when implementation begins. The Containers product specifically should be validated as GA and suitable for this use case.