If you want to access FC Agent Sandbox 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 FC Agent Sandbox.
After a custom domain is bound, you can use:
A control-plane domain to access FC Agent Sandbox 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 FC Agent Sandbox 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 FC Agent Sandbox APIs. |
SDK domain | example.com | The base domain used by the SDK to construct sandbox service addresses. |
Limits
When you bind a custom domain to FC Agent Sandbox, you must select the same region where the sandbox is deployed.
The control-plane domain currently supports only a single domain name prefixed with
api., such asapi.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.Only HTTPS is supported.
You must upload a certificate that covers the data-plane wildcard domain, such as
*.example.com. A single-domain certificate that only coversapi.example.comis not sufficient.The private key must be an unencrypted RSA PEM key. If your private key is in the
-----BEGIN PRIVATE KEY-----format, convert it to-----BEGIN RSA PRIVATE KEY-----first.Internationalized domain names are not supported.
By default, one primary account can bind up to 5 FC Agent Sandbox 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.
Example of converting the private key format:
openssl rsa -in pkcs8.key -out pkcs1.key1. Add a custom domain
Sign in to the Function Compute FC Agent Sandbox console.
In the left-side navigation pane, choose .
Select the region where your FC Agent Sandbox instances are deployed.
Click Add Custom Domain.
On the Add Custom Domain page, enter the control-plane domain, for example
api.example.com.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 FC Agent Sandbox. 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 FC Agent Sandbox.
| CNAME type | Host record | Record type | Example record value |
| Control-plane CNAME | api | CNAME | api.cn-beijing.e2b.fc.aliyuncs.com |
| Data-plane CNAME | * | CNAME | {AccountID}.cn-beijing.e2b.fc.aliyuncs.com |
Example: if your primary account ID is 119085698835**** and your FC Agent Sandbox region is China North 2 (Beijing), the data-plane CNAME can be configured as:
119085698835****.cn-beijing.e2b.fc.aliyuncs.comAfter 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.comHere, test.example.com is used to verify whether the wildcard resolution for *.example.com has taken effect.
3. Configure an HTTPS certificate
FC Agent Sandbox 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 successfully, replace the API endpoint and data-plane base domain in the SDK with the custom domain that you bound.
TypeScript example:
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}`);Python example:
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.com5. Verify the custom domain
After the configuration is complete, verify it by following these steps:
Use the SDK or OpenAPI to create an FC Agent Sandbox instance.
Start an HTTP service inside the sandbox, for example on port
8000.Call
sandbox.getHost(8000)to get the access domain.Use a browser or
curlto accesshttps://{port}-{sandboxId}.example.com.
Example:
curl -v https://8000-sandbox-id.example.comIf 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. |
| 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 | Convert it with openssl rsa -in pkcs8.key -out pkcs1.key and 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 prependhttps://when accessing it.Custom domains are suitable for production or long-lived access scenarios. For temporary debugging, you can still use the default FC Agent Sandbox domain.
Do not expose sensitive data, internal debugging endpoints, or long-lived credentials through unauthenticated port services.