Skip to main content
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.
Example: 8080-sandboxid.mydomain.com -> 8080-sandboxid.e2b.app

Prerequisites

  • Domain name registered and configured with Cloudflare DNS.
  • Cloudflare API Token that allows you to manage DNS records.

GCP VM setup

  1. Create a VM instance by running the following command:
    Replace your-project-id with your actual project ID.
  2. After the VM is created, you can connect to it using the following command:
    Replace your-project-id with your actual project ID.

Server setup

  1. Install the latest stable version of Docker:
  2. Create a Dockerfile that will be used to build the Caddy server image with Cloudflare DNS:
    Dockerfile
  3. Create a Docker Compose file that will be used to start the Caddy server:
    docker-compose.yml
  4. Create a Caddyfile for proxying the requests to the Sandboxes:
    Replace *.mydomain.com with your actual wildcard domain name.
    Caddyfile
  5. Create a .env file that will be used to store the Cloudflare API Token:
    .env
  6. 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.
  1. Create a new Sandbox using E2B CLI:
  2. Install and run a simple HTTP server in the sandbox:
  3. Visit the sandbox URL in your browser: https://80-sandboxid.mydomain.com. You should see the default nginx welcome page.