Custom Domains

Updated at:

If you want to access Agent Sandbox Flash Edition through a fixed domain name in production, or use your own certificate for web services running inside a sandbox, you can bind a custom domain to Agent Sandbox Flash Edition.

Note

Custom domains are a capability of Agent Sandbox Flash Edition that extends beyond E2B.

After a custom domain is bound, you can use:

  • A control-plane domain to access Agent Sandbox Flash Edition APIs, for example https://api.example.com.

  • A data-plane domain to access services inside a sandbox, for example https://{port}-{sandboxId}.example.com.

Using example.com as an example:

Purpose

Example

Description

Control-plane domain

api.example.com

Used for API requests such as creating, querying, and deleting Agent Sandbox Flash Edition instances.

Data-plane domain

*.example.com

Used to access services exposed on specific ports inside a sandbox.

SDK apiUrl

https://api.example.com

The endpoint used by the SDK to access Agent Sandbox Flash Edition APIs.

SDK domain

example.com

The data-plane base domain used by the SDK to construct the address of a service in a sandbox, such as example.com. This is different from the wildcard domain *.example.com.

Limits

  • When you bind a custom domain to Agent Sandbox Flash Edition, you must select the region where Agent Sandbox Flash Edition is deployed.

  • The control-plane domain currently supports only a single domain name prefixed with api., such as api.example.com.

  • The data-plane domain is the wildcard domain obtained by removing the api. prefix from the control-plane domain, for example *.example.com.

  • Custom domains must use HTTPS.

  • Custom domains require a certificate that covers the data-plane wildcard domain, such as *.example.com. A single-domain certificate that covers only api.example.com does not meet this requirement.

  • The private key must be an unencrypted RSA PEM key. If the private key is in the -----BEGIN PRIVATE KEY----- format, convert it to -----BEGIN RSA PRIVATE KEY----- first.

  • Custom domains do not support internationalized domain names.

  • By default, one primary account can bind up to 5 Agent Sandbox Flash Edition custom domains. Contact support if you need a higher quota.

  • Your custom domain must complete ICP filing or filing access as required by the console validation result.

Convert the RSA private key to the PKCS#1 format by using OpenSSL 3.x:

openssl rsa -traditional -in pkcs8.key -out pkcs1.key

After the conversion, run the following commands to check only the key format and the certificate match, without printing the private key:

head -1 pkcs1.key
openssl rsa -in pkcs1.key -noout -modulus | openssl md5
openssl x509 -in server.crt -noout -modulus | openssl md5

The first line must be -----BEGIN RSA PRIVATE KEY-----. If the last two MD5 values are identical, the private key matches the certificate.

1. Add a custom domain

  1. Sign in to the Agent Sandbox console.

  2. In the left-side navigation pane, choose Flash Edition > Domain Name Management.

  3. Select the region where your Agent Sandbox Flash Edition instances are deployed.

  4. Click Create a domain name.

  5. On the Create a domain name page, enter the root domain, which is the data-plane base domain, for example example.com. After the domain is created, the control-plane domain is api.example.com.

  6. Follow the prompts to obtain the control-plane CNAME and data-plane CNAME for DNS configuration in the next step.

Important: The custom domain must use the same region as Agent Sandbox Flash Edition. Otherwise DNS resolution and certificate validation may fail.

2. Configure DNS resolution

Sign in to the Alibaba Cloud DNS console and point your custom domain to the CNAME records provided by Agent Sandbox Flash Edition.

CNAME type

Host record

Record type

Example record value

Control-plane CNAME

api

CNAME

api.cn-beijing.sandbox.aliyuncs.com

Data-plane CNAME

*

CNAME

{AccountID}.cn-beijing.sandbox.aliyuncs.com

Example: if the primary account ID is 119085698835**** and the region of Agent Sandbox Flash Edition is China (Beijing), the data-plane CNAME can be configured as:

119085698835****.cn-beijing.sandbox.aliyuncs.com

After the configuration is complete, wait for DNS propagation before you submit or verify the domain. You can use the following commands to check the resolution result:

dig +short CNAME api.example.com
dig +short CNAME test.example.com

Here, test.example.com is used to verify whether the wildcard resolution for *.example.com has taken effect.

3. Configure an HTTPS certificate

Agent Sandbox Flash Edition custom domains always use HTTPS. Upload the certificate and private key when you add the domain.

Setting

Description

Certificate name

Used to identify the uploaded certificate.

PEM certificate content

Enter the full certificate chain, including -----BEGIN CERTIFICATE----- and -----END CERTIFICATE-----.

PEM private key

Enter the unencrypted RSA private key, including -----BEGIN RSA PRIVATE KEY----- and -----END RSA PRIVATE KEY-----.

TLS protocol version

TLS 1.2 or later is recommended.

Certificate requirements:

  • The certificate must be valid.

  • The certificate and private key must match.

  • The certificate must cover the data-plane wildcard domain. For example, if the control-plane domain is api.example.com, the certificate must cover *.example.com.

4. Use a custom domain in the SDK

After the domain is added, replace the control-plane domain and the data-plane base domain in the SDK with the custom domain that you bound:

import { Sandbox } from "e2b";

const sandbox = await Sandbox.create("code-interpreter-v1", {
  apiKey: process.env.E2B_API_KEY,
  apiUrl: "https://api.example.com",
  domain: "example.com",
});

const host = sandbox.getHost(8000);
console.log(`https://${host}`);
import os

from e2b import Sandbox

sandbox = Sandbox.create(
    template="code-interpreter-v1",
    api_key=os.environ["E2B_API_KEY"],
    api_url="https://api.example.com",
    domain="example.com",
)

host = sandbox.get_host(8000)
print(f"https://{host}")

If the sandbox ID is sandbox-id and the exposed port is 8000, the SDK returns an address in the following format:

https://8000-sandbox-id.example.com

5. Verify the custom domain

After the configuration is complete, verify it by following these steps:

  1. Use the SDK or OpenAPI to create an Agent Sandbox Flash Edition instance.

  2. Start an HTTP service inside the sandbox, for example on port 8000.

  3. Call sandbox.getHost(8000) to get the access domain.

  4. Use a browser or curl to access https://{port}-{sandboxId}.example.com.

Example:

curl -v https://8000-sandbox-id.example.com

If you receive a response from the service running inside the sandbox, the data-plane domain is working.

FAQ

Issue

Possible cause

Resolution

CNAME validation fails when you add the domain

DNS is not configured, the record value is incorrect, or DNS propagation is not complete

Verify that the control-plane CNAME points to the target shown in the console, then retry after DNS propagation completes. If the submission is rejected although the configuration has not changed, submit the request again. You do not need to change the DNS records.

The certificate does not match during HTTPS access

The certificate does not cover the data-plane wildcard domain

Upload a wildcard certificate that covers *.example.com.

The private key format is invalid

The private key is not an unencrypted RSA PEM key

In OpenSSL 3.x, convert the key with openssl rsa -traditional -in pkcs8.key -out pkcs1.key, and then upload it again.

The SDK still returns the default domain

apiUrl or domain is not configured in the SDK

Set apiUrl to the control-plane domain and domain to the data-plane base domain.

The data-plane address cannot be accessed

The wildcard CNAME is not effective, or the service inside the sandbox is not listening on the target port

Check the *.example.com resolution result and confirm that the service inside the sandbox is running.

The domain quota is reached

Multiple custom domains are already bound under the current primary account

Delete unused domains or contact support to increase the quota.

Notes

  • sandbox.getHost(port) returns only the host name. In most cases, you need to prepend https:// when accessing it.

  • Custom domains are suitable for production or long-lived access scenarios. For temporary debugging, you can still use the default Agent Sandbox Flash Edition domain.

  • Do not expose sensitive data, internal debugging endpoints, or long-lived credentials through unauthenticated port services.