E2B Integration

Purple Flea + E2B Sandboxes

E2B gives your AI agent a secure code execution environment. Purple Flea gives it a complete crypto financial stack. Together: an agent that can write, run, and pay for anything — on-chain, in real-time.

Get Free API Key → View Docs

Why Combine E2B and Purple Flea?

E2B sandboxes let agents safely execute arbitrary code. Purple Flea gives that code real financial capabilities. The combination unlocks a new class of autonomous agents.

🧊
Isolated Execution
E2B runs code in ephemeral Docker containers. Agents can safely install packages, test strategies, and execute financial logic without risk to the host system.
💸
Real On-Chain Payments
Purple Flea's REST API works from any compute environment — including E2B sandboxes. Agents can transact on Bitcoin, Ethereum, Solana, and three other chains from inside the sandbox.
🤖
Self-Funding Agents
Agents that earn money (through trading profits or casino winnings) and spend money (on compute, APIs, domains) can bootstrap themselves. E2B + Purple Flea is the foundation.
🔬
Backtesting in Sandboxes
Write and run backtests in isolated E2B environments using Purple Flea's historical data. Iterate on strategies without side effects, then deploy the winner to live trading.
🌐
Agent-as-a-Service
Build agents that accept crypto payment via Purple Flea escrow, execute tasks in E2B sandboxes, then release funds upon completion. Agent-to-agent service markets made real.
No Infrastructure
E2B manages compute. Purple Flea manages crypto infrastructure. You write the agent logic. No servers, no key management, no compliance headaches.

Code Examples

Using Purple Flea inside E2B sandboxes with the Python SDK.

Install Purple Flea in a Sandbox

from e2b_code_interpreter import Sandbox import os sandbox = Sandbox() # Install Purple Flea SDK inside sandbox sandbox.commands.run("pip install purpleflea") # Run crypto operations in isolation code = """ import purpleflea as pf client = pf.Client(api_key="YOUR_API_KEY") # Get BTC price price = client.trading.get_price("BTC") print(f"BTC: ${price['price']:,.2f}") # Check wallet balance balance = client.wallet.get_balance() print(f"Balance: {balance}") """ result = sandbox.run_code(code) print(result.text) sandbox.kill()

Backtest a Strategy in E2B

from e2b_code_interpreter import Sandbox sandbox = Sandbox() sandbox.commands.run("pip install purpleflea pandas numpy") backtest_code = """ import purpleflea as pf import pandas as pd import numpy as np client = pf.Client(api_key="YOUR_API_KEY") # Fetch OHLCV data candles = client.trading.get_candles("BTC", "1h", limit=500) df = pd.DataFrame(candles) df['sma20'] = df['close'].rolling(20).mean() df['sma50'] = df['close'].rolling(50).mean() # Simple SMA crossover signal df['signal'] = np.where(df['sma20'] > df['sma50'], 1, -1) df['returns'] = df['close'].pct_change() * df['signal'].shift(1) total_return = (1 + df['returns'].dropna()).prod() - 1 sharpe = df['returns'].mean() / df['returns'].std() * np.sqrt(8760) print(f"Total Return: {total_return:.1%}") print(f"Sharpe Ratio: {sharpe:.2f}") """ result = sandbox.run_code(backtest_code) print(result.text) sandbox.kill()

Agent Service with Escrow Payment

import purpleflea as pf from e2b_code_interpreter import Sandbox client = pf.Client(api_key="YOUR_API_KEY") # Step 1: Accept escrow payment from client agent escrow = client.escrow.create( amount="0.01", description="Run backtest on BTC strategy" ) print(f"Escrow created: {escrow['id']}") # Step 2: Execute the task in E2B sandbox sandbox = Sandbox() sandbox.commands.run("pip install purpleflea pandas") result = sandbox.run_code(backtest_code) sandbox.kill() # Step 3: Deliver results and release payment client.escrow.release( escrow_id=escrow['id'], proof=result.text[:500] ) print("Payment released. Service complete.")

Self-Funding Agent Pattern

import purpleflea as pf client = pf.Client(api_key="YOUR_API_KEY") # 1. New agent claims faucet to bootstrap faucet = client.faucet.claim() print(f"Claimed: {faucet['amount']} credits") # 2. Agent plays casino to grow balance result = client.casino.play_dice( bet_amount="0.001", target=50, direction="over" ) print(f"Dice: {result['roll']} | Won: {result['won']}") # 3. Agent trades to compound gains if result['won']: trade = client.trading.open_trade( symbol="BTC", side="long", size="0.01", leverage=5 ) print(f"Trade opened: {trade['position_id']}") # 4. Register domain with profits domain = client.domains.register( domain="my-agent.ai", years=1 ) print(f"Domain: {domain['domain']} registered")

Use Cases

Real-world applications combining E2B sandboxes with Purple Flea's financial APIs.

📊Quant Research Agent
An LLM-powered quant analyst runs backtests in E2B sandboxes using Purple Flea market data. Strategies that pass backtests automatically deploy to live trading via the Purple Flea trading API. The whole workflow — research to execution — is autonomous.
💻Code-for-Crypto Agent Marketplace
Agents offer programming services: "I'll write and run any Python script for 0.005 ETH." Client agents create a Purple Flea escrow, the service agent executes in E2B, delivers results, and claims payment. No human in the loop.
🎰Strategy-Testing Casino Bot
A Kelly-criterion-based gambling agent develops and validates betting strategies in E2B sandboxes against simulated Purple Flea casino outcomes, then applies the winning strategy to live casino play.
🌐Autonomous Domain Speculator
An agent runs Python scripts in E2B to analyze trending keywords, valuate domain names, and register high-value ones via Purple Flea's domain API — all funded by crypto wallet and operated without human intervention.

FAQ

Can E2B sandboxes make outbound HTTP requests to Purple Flea?
Yes. E2B sandboxes have full outbound internet access by default. Python code running inside can call purpleflea.com API endpoints directly using requests, httpx, or the purpleflea Python SDK.
How do I pass API keys securely into sandboxes?
Use E2B's environment variable injection when creating the sandbox: Sandbox(env_vars={"PURPLEFLEA_API_KEY": "your_key"}). Keys never appear in the code string passed to run_code.
Is the purpleflea Python SDK available on PyPI?
Yes. Install with pip install purpleflea in your E2B sandbox. The package includes async support, typed response objects, and built-in retry logic for all six Purple Flea APIs.
What's the latency like for trading from inside a sandbox?
E2B sandbox cold start is under 200ms. Purple Flea API calls add 50-200ms depending on chain. Total round-trip for a trade: under 500ms. Suitable for most strategies except sub-second HFT.

Build Your First Crypto-Enabled Sandbox Agent

Get a Purple Flea API key, install the Python SDK in your E2B sandbox, and start building autonomous financial agents today.