{"slug": "why-i-built-e2bgateway-solving-ai-agent-sandbox-vendor-lock-in", "title": "Why I Built E2BGateway: Solving AI Agent Sandbox Vendor Lock-in", "summary": "A developer built E2BGateway, an open-source gateway that allows AI agents to use the official E2B SDK with any sandbox backend, avoiding vendor lock-in. The gateway supports multiple backends including E2B Cloud, Kubernetes-native agent-sandbox, and container-based OpenSandbox, requiring only a one-line change to the E2B_API_URL environment variable.", "body_md": "If you're building AI agents that execute code, you've probably heard of [E2B](https://e2b.dev). It's an awesome platform for running AI agent code in secure sandboxes. But there's a catch: **you're locked into their cloud**.\n\nThat was a problem for me. I needed flexibility to run sandboxes on my own Kubernetes cluster, switch between providers, and avoid being tied to a single vendor.\n\nSo I built ** E2BGateway** – an open-source gateway that lets you use the official E2B SDK with any sandbox backend.\n\nIn this article, I'll share why I built it, how it works, and how it can help you build more flexible AI agent systems.\n\nWhen building AI agents, you often need to execute code in isolated environments. E2B provides excellent sandbox infrastructure, but integrating with it means:\n\n```\n# Your code is now tied to E2B Cloud\nos.environ[\"E2B_API_URL\"] = \"https://api.e2b.dev\"\nos.environ[\"E2B_API_KEY\"] = \"your-e2b-api-key\"\n\nfrom e2b_code_interpreter import Sandbox\nsbx = Sandbox.create()\nresult = sbx.run_code(\"print('Hello E2B!')\")\n```\n\n**What if you want to:**\n\nYou'd have to **rewrite your entire codebase** to use a different sandbox provider. That's vendor lock-in.\n\nE2BGateway acts as an abstraction layer between your AI agents and sandbox backends:\n\n```\nYour AI Agent Code (E2B SDK)\n        ↓\nE2BGateway (you control this)\n        ↓\n┌───────────────────────────────────────┐\n│  Choose Your Backend:                 │\n│  • E2B Cloud (existing integration)  │\n│  • agent-sandbox (Kubernetes-native) │\n│  • OpenSandbox (container-based)     │\n└───────────────────────────────────────┘\n```\n\nThe magic? **Your code doesn't change at all.** Just point the E2B SDK at your gateway:\n\n```\n# Before (E2B Cloud only)\nos.environ[\"E2B_API_URL\"] = \"https://api.e2b.dev\"\n\n# After (any backend)\nos.environ[\"E2B_API_URL\"] = \"https://your-gateway.example.com\"\n\n# Same code works everywhere!\nfrom e2b_code_interpreter import Sandbox\nsbx = Sandbox.create(template=\"code-interpreter\")\nresult = sbx.run_code(\"print('Hello from E2BGateway!')\")\nsbx.kill()\n```\n\nE2BGateway supports multiple sandbox backends:\n\n| Backend | Type | Use Case |\n|---|---|---|\nE2B Cloud |\nSaaS | Quick start, managed service |\nagent-sandbox |\nKubernetes CRD | Self-hosted, K8s-native |\nOpenSandbox |\nContainer-based | Lightweight, flexible |\n\nAlready using E2B SDK? Migration is literally **one line of code**:\n\n```\nos.environ[\"E2B_API_URL\"] = \"https://your-gateway.com\"\n```\n\nThat's it. No code changes, no refactoring, no headaches.\n\nBuilt for production workloads:\n\nImplements the complete E2B REST API:\n\n`POST/GET/DELETE /api/v1/sandboxes`\n\n)`POST /api/v1/sandboxes/{id}/code`\n\n)`POST /api/v1/sandboxes/{id}/commands`\n\n)`POST/GET /api/v1/sandboxes/{id}/files/*`\n\n)`GET/POST/DELETE /api/v1/templates`\n\n)Let's dive into how E2BGateway works under the hood.\n\n```\n┌─────────────────────────────────────────┐\n│           E2BGateway                    │\n│                                         │\n│  ┌──────────────────────────────────┐  │\n│  │  Request Pipeline                │  │\n│  │  Auth → RateLimit → Router      │  │\n│  └──────────────┬───────────────────┘  │\n│                 │                       │\n│  ┌──────────────▼───────────────────┐  │\n│  │  Protocol Translator            │  │\n│  │  E2B Protocol → Backend API     │  │\n│  └──────────────┬───────────────────┘  │\n│                 │                       │\n│  ┌──────────────▼───────────────────┐  │\n│  │  Backend Adapters               │  │\n│  │  ┌─────────┐  ┌─────────┐       │  │\n│  │  │ E2B     │  │ K8s     │ ...   │  │\n│  │  └────┬────┘  └────┬────┘       │  │\n│  └───────┼─────────────┼───────────┘  │\n└──────────┼─────────────┼──────────────┘\n           │             │\n           ▼             ▼\n      E2B Cloud    Kubernetes Cluster\n```\n\nI chose Go for several reasons:\n\n**Problem**: E2B Cloud costs are high for development/testing.\n\n**Solution**: Use E2BGateway to route:\n\n```\n# Development environment\nos.environ[\"E2B_API_URL\"] = \"https://dev-gateway.internal.com\"\n\n# Production environment\nos.environ[\"E2B_API_URL\"] = \"https://prod-gateway.example.com\"\n```\n\n**Problem**: Sensitive code can't leave your infrastructure.\n\n**Solution**: Run E2BGateway entirely on-premises with agent-sandbox backend.\n\n```\n# Deploy on your Kubernetes cluster\nhelm install e2bgateway ./deploy/helm/e2bgateway\n\n# All sandboxes run on your infrastructure\n# No data leaves your network\n```\n\n**Problem**: Different tenants need different sandbox backends.\n\n**Solution**: Use E2BGateway's routing rules to route tenants to appropriate backends.\n\n```\n# e2bgateway.yaml\nroutes:\n  - tenant: enterprise-corp\n    backend: agent-sandbox  # Their own K8s cluster\n  - tenant: startup-inc\n    backend: e2b-cloud  # Managed service\n  - tenant: default\n    backend: opensandbox  # Shared infrastructure\n```\n\nReady to try E2BGateway? Here's how to get started in 5 minutes.\n\n```\n# Clone the repository\ngit clone https://github.com/e2bgateway/e2bgateway.git\ncd e2bgateway\n\n# Build\nmake build\n\n# Run locally\nmake run\n```\n\nCreate a config file:\n\n```\n# config.yaml\nserver:\n  port: 8080\n\nbackends:\n  - name: e2b-cloud\n    type: e2b\n    config:\n      api_url: https://api.e2b.dev\n      api_key: your-e2b-api-key\n\n  - name: k8s-sandbox\n    type: agent-sandbox\n    config:\n      kubeconfig: ~/.kube/config\n\nrouting:\n  default_backend: e2b-cloud\npython\nimport os\n\n# Point to your gateway\nos.environ[\"E2B_API_URL\"] = \"http://localhost:8080\"\nos.environ[\"E2B_API_KEY\"] = \"your-gateway-api-key\"\n\n# Use E2B SDK as normal\nfrom e2b_code_interpreter import Sandbox\n\nsbx = Sandbox.create(template=\"code-interpreter\")\nresult = sbx.run_code(\"\"\"\nimport pandas as pd\ndf = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})\nprint(df.describe())\n\"\"\")\nprint(result.text)\nsbx.kill()\n```\n\nThat's it! You're now running sandboxes through E2BGateway.\n\nI'm just getting started with E2BGateway. Here's what's on the roadmap:\n\nE2BGateway is open source (Apache 2.0) and I'd love your help!\n\n**Ways to contribute:**\n\n**Check out the repo**: [https://github.com/e2bgateway/e2bgateway](https://github.com/e2bgateway/e2bgateway)\n\nVendor lock-in is a real problem in the AI agent ecosystem. E2BGateway gives you the flexibility to:\n\n✅ Use the E2B SDK you already know\n\n✅ Choose the sandbox backend that fits your needs\n\n✅ Switch backends without rewriting code\n\n✅ Run sandboxes on your own infrastructure\n\n✅ Optimize costs and maintain data sovereignty\n\nWhether you're building AI agents for production or experimenting with local LLMs, E2BGateway gives you the freedom to choose.\n\n**Give it a try**: [https://github.com/e2bgateway/e2bgateway](https://github.com/e2bgateway/e2bgateway)\n\n**Let me know what you think!** Drop a comment below or open an issue on GitHub.\n\n*P.S. E2BGateway has been submitted to awesome-go (PR #6533), awesome-kubernetes (PR #1130), and awesome-mcp-gateways (PR #67). If you find it useful, consider giving it a star!* ⭐\n\n**Title**: Why I Built E2BGateway: Solving AI Agent Sandbox Vendor Lock-in\n\n**Tags**:\n\n**Cover Image**: (Optional - use project logo or architecture diagram)\n\n**Canonical URL**: [https://github.com/e2bgateway/e2bgateway](https://github.com/e2bgateway/e2bgateway)\n\n**Series**: (Optional - if you plan to write more articles about E2BGateway)", "url": "https://wpnews.pro/news/why-i-built-e2bgateway-solving-ai-agent-sandbox-vendor-lock-in", "canonical_source": "https://dev.to/dongjiang/why-i-built-e2bgateway-solving-ai-agent-sandbox-vendor-lock-in-51k6", "published_at": "2026-07-29 04:19:35+00:00", "updated_at": "2026-07-29 04:35:18.486489+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "ai-infrastructure"], "entities": ["E2B", "E2BGateway", "agent-sandbox", "OpenSandbox", "Kubernetes"], "alternates": {"html": "https://wpnews.pro/news/why-i-built-e2bgateway-solving-ai-agent-sandbox-vendor-lock-in", "markdown": "https://wpnews.pro/news/why-i-built-e2bgateway-solving-ai-agent-sandbox-vendor-lock-in.md", "text": "https://wpnews.pro/news/why-i-built-e2bgateway-solving-ai-agent-sandbox-vendor-lock-in.txt", "jsonld": "https://wpnews.pro/news/why-i-built-e2bgateway-solving-ai-agent-sandbox-vendor-lock-in.jsonld"}}