- HTTPS: The platform terminates TLS at its edge with a certificate it provisions and renews, then forwards the request to your port as cleartext HTTP.
- TLS passthrough: The platform routes the connection to your port by Server Name Indication (SNI) without decrypting it. Your workload terminates TLS and owns its own certificates.
Choose authentication
These examples run on serverless capacity unless a section specifies CoreWeave Kubernetes Service (CKS). Choose the credential for the account that owns your sandboxes. See Choose and get credentials to obtain a key or token. Save the configuration for your language beside the scripts you run from this page. Python examples importAUTH from sandbox_auth.py. TypeScript examples import client from sandbox-client.mts. These files select authentication without storing your credential. For Python, use an active virtual environment. For TypeScript, first install the client with npm install @coreweave/cwsandbox.
- Forge API key
- CoreWeave API access token
Use your Forge API key with the SDK’s
wandb integration. Replace [WANDB-API-KEY] with your API key:- Python
- TypeScript
sandbox_auth.py
placement_mode="cks" on sandbox creation or in SandboxDefaults. In TypeScript, choose the CoreWeave token and set a nonempty runnerIds array to select CKS. Creating a Python session with auth=AUTH also authenticates the sandboxes it owns. Keep the same credential when reconnecting, listing, or cleaning up sandboxes.
The Python share-token example requires cwsandbox 1.16.0 or later and a deployment with HTTPS share-token support. The credential you configure in this section authenticates SDK operations such as creating and deleting sandboxes. It’s separate from the endpoint share token that callers use to access a protected HTTPS URL.
Compare the two kinds
Declare an endpoint
Declare endpoints in theservices list when you create the sandbox. Ports are fixed for the sandbox’s lifetime, and no call exposes a port on a sandbox that is already running.
To give a service a public endpoint, set visibility=ServiceVisibility.PUBLIC and an endpoint value on it. A plain service has no endpoint value. For example, Service(port=8080, name="web") leaves visibility and endpoint unset: It declares a container-local port without requesting external exposure. Visibility on a plain service controls reachability through the deployment’s service networking. It doesn’t request a public HTTPS URL or TLS passthrough address.
To require a token, use EndpointAuth.SHARE_TOKEN as shown in Connect with a share token. For an HTTPS endpoint without platform caller authentication, set kind=EndpointKind.HTTPS and auth=EndpointAuth.OPEN:
- Python
- TypeScript
kind=EndpointKind.TLS_PASSTHROUGH and leave auth unset. The command you run must terminate TLS on the port itself, because the platform forwards the connection without decrypting it:
- Python
- TypeScript
OPEN and SHARE_TOKEN HTTPS endpoints. The following rules apply:
- Ports and names must be unique across all
servicesentries, including names generated for unnamed ports. - Entries with an
endpointrequirevisibility=PUBLIC. Setprotocol=TCPor leaveprotocolunset. The platform rejectsUDPandSCTPendpoints. - Plain entries without an
endpointcan leave visibility unset or usePRIVATE,PUBLIC, orCUSTOM. They can declareTCP,UDP, orSCTP. An unset protocol defaults toTCP. Actual exposure depends on deployment capabilities and policy. These fields don’t create a public endpoint. - Don’t mix exposed plain services with endpoint entries. In a sandbox with endpoints, leave visibility unset on any plain service. Without endpoints, use at most one exposed visibility value across plain services.
- Omit
authandrequest_timeout_secondsfor TLS passthrough. In Python, passNonerather than0. The SDK rejects a set timeout, including0. - A platform limit caps how many services one sandbox declares. Operators configure the cap for their deployment.
Connect with a share token
To require platform authentication for an HTTPS endpoint, setauth=EndpointAuth.SHARE_TOKEN. Read sandbox.endpoint_share_token from the handle that creates the sandbox, and send its as_headers() result with each request. This helper sets the X-Sandbox-Share-Token header. The platform checks the token before forwarding the request to your HTTP service.
In TypeScript, set auth: "share_token" and send sandbox.endpointShareToken in the X-Sandbox-Share-Token request header.
The token is returned at creation. Get, list, and Sandbox.from_id() don’t return it. The original handle retains it across wait() and get_status(). If the initial response omits it, sandbox.start().result() retries recovery on the same create handle. If recovery still returns no token, stop the sandbox and create another.
Keep the token secret: The dictionary returned by as_headers() contains the credential. Don’t log this dictionary.
The following Python example starts a 5-minute HTTP service behind a protected HTTPS endpoint. It waits for URL assignment and retries authenticated requests while the application and route become ready. After a successful request, it verifies that an anonymous request is rejected. The context manager stops the sandbox when the example exits.
auth=EndpointAuth.OPEN, an anonymous request succeeds once the service is ready. No share token is required. To change the auth mode, create a new sandbox. One sandbox can contain both modes, and the token protects only its SHARE_TOKEN endpoints.
The generated Endpoint reference describes Python SDK version 1.14.2, which supports OPEN but predates SHARE_TOKEN.
Read the assigned address
The platform assigns the address. You can’t choose the hostname or supply your own domain. Read it back from the sandbox rather than constructing it, because the DNS zone differs per cluster and isn’t part of the API contract. TLS passthrough addresses arrive onservice_addresses as host:port, and HTTPS URLs arrive on service_urls. The two lists stay separate: A TLS endpoint never appears in service_urls.
- Python
- TypeScript
8443 and clients connect to 443.
The two kinds become readable at different points in the sandbox’s startup:
- A TLS passthrough address is assigned when the sandbox is created, so it is on the create response and stays available while the sandbox is creating or running.
- An HTTPS URL is available once its route has a hostname, while the sandbox is creating or running. Call
get_status()in Python orinspect()in TypeScript in a loop until the URL appears or your own deadline passes. - Neither one means the application is serving. The platform doesn’t wait for your process to bind the port before reporting the sandbox as running, so retry your first connection.
Connect to a TLS passthrough endpoint
Because the platform doesn’t decrypt the connection, the certificate a client receives is the one your workload presents. Two things follow for the client:- Send the endpoint host as the SNI server name. The platform routes on SNI alone, so a connection that omits it, or sends a different name, doesn’t reach your sandbox.
- Trust the workload’s certificate. The endpoint hostname is platform-assigned, so a certificate you issue yourself doesn’t match it unless you issue it for that hostname. Configure the client to trust your own certificate authority, or pin the certificate.
[ENDPOINT-ADDRESS] with the address you read from service_addresses, and [PATH-TO-CA-CERT] with the path to the certificate authority that signed your workload’s certificate:
Endpoint lifetime
An endpoint lives as long as the sandbox that owns it:- It’s keyed to the sandbox, not to a Pod. If the underlying Pod restarts, the address stays the same.
- Deleting the sandbox removes the endpoint. The address doesn’t move to another sandbox, and a new sandbox gets a new address.
- Nothing is reserved between sandboxes. You can’t hold a hostname for reuse.
Troubleshoot create failures
If no runner in your fleet supports the endpoint kind you requested, the create call fails rather than starting a sandbox with the endpoint silently dropped.Related pages
- Sandbox configuration: resources, ports, secrets, and timeouts.
- Sandbox architecture: how runners, profiles, and the control plane interact.
- Sandbox lifecycle: the states a sandbox moves through.