How to set up a custom domain for Sandboxes hosted on E2B. We will set up a GCP VM running Caddy server with Docker and Cloudflare DNS to proxy the requests to the Sandboxes.Documentation Index
Fetch the complete documentation index at: https://e2b-mishushakov-replace-all-traffic-syntax.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- Domain name registered and configured with Cloudflare DNS.
- Cloudflare API Token that allows you to manage DNS records.
GCP VM setup
-
Create a VM instance by running the following command:
Replace
your-project-idwith your actual project ID. -
After the VM is created, you can connect to it using the following command:
Replace
your-project-idwith your actual project ID.
Server setup
-
Install the latest stable version of Docker:
-
Create a Dockerfile that will be used to build the Caddy server image with Cloudflare DNS:
Dockerfile
-
Create a Docker Compose file that will be used to start the Caddy server:
docker-compose.yml
-
Create a Caddyfile for proxying the requests to the Sandboxes:
Replace
*.mydomain.comwith your actual wildcard domain name.Caddyfile -
Create a .env file that will be used to store the Cloudflare API Token:
.env
-
Build and start the Caddy server:
Domain setup
Log into the Cloudflare dashboard and create a new A wildcard DNS record pointing to the IP address of the GCP VM.Replace
GCP_VM_IP with the IP address of the GCP VM.It may take a few minutes for the DNS record to propagate and for the certificate to be issued.
If you have existing AAAA (IPv6) records for this domain name, make sure they are either removed or updated to point to the GCP VM.
DNS
Testing the setup
We will create a new Sandbox on E2B and install a simple HTTP server in it.-
Create a new Sandbox using E2B CLI:
-
Install and run a simple HTTP server in the sandbox:
-
Visit the sandbox URL in your browser:
https://80-sandboxid.mydomain.com. You should see the default nginx welcome page.