All Products
Search
Document Center

Container Compute Service:Multi-tenancy management

Last Updated:Oct 13, 2026

When multiple tenants share the same Agent Sandbox cluster, each tenant is mapped to an independent Kubernetes Namespace through a Team and holds its own API key as an access credential. Administrators and tenants can create, query, and revoke API keys through HTTP interfaces.

Overview

ack-sandbox-manager provides a set of E2B-compatible HTTP interfaces for managing API keys and Teams. Cluster administrators and tenants can use these interfaces to programmatically create API keys, query their Teams, and revoke unused keys.

These interfaces have no accompanying E2B SDK and no corresponding Kubernetes Custom Resource Definition (CRD). You must call them directly through HTTP.

Team

A Team is the authorization boundary for an API key. In Agent Sandbox, a Team is uniquely identified by its name, which maps directly to a Kubernetes Namespace.

  • The built-in admin Team is cluster-level and managed by the administrator. Its admin API key is initialized when ack-sandbox-manager starts.

  • Any other Team name must correspond to an existing Kubernetes Namespace. When a tenant creates an API key for Team foo, Namespace foo must already exist. Otherwise, the request returns an error.

A namespace's uniqueness already provides a sufficient isolation boundary. Therefore, a Team's unique identifier (UUID) is retained only as display metadata and is not used for authentication or resource lookups.

API key

An API key is a long-term access credential held by a Team. When a client calls any interface of ack-sandbox-manager, it must include the key in the X-API-KEY request header. An API key determines:

  • Which Team the caller belongs to.

  • Whether the caller is a regular tenant or a cluster administrator, that is, whether the caller belongs to the admin Team.

  • The scope of Sandboxes that the caller can access. Regular tenants can access only Sandboxes created with their own API keys, whereas administrators can access all Sandboxes.

Authorization model

Role

List keys for the current Team

List Teams

Create a key for the current Team

Create a key for another Team

Delete a key for the current Team

Delete the admin API key

Administrator (admin Team)

Supported

Supported (all Teams)

Supported

Supported

Supported

Not supported (denied)

Regular tenant

Supported

Supported (only the caller's Team)

Supported

Not supported

Supported

Not supported

Important

The built-in admin API key cannot be deleted under any circumstances, which protects cluster manageability.

Prerequisites

  • Go to Add-ons for the target cluster. Confirm that ack-sandbox-manager is installed and upgraded to v0.6.0 or later. Then configure the following settings on the add-on's Configuration page:

    • Select Whether to enable E2B_API_KEY authentication to enable API key authentication.

    • Configure adminApiKey (administrator API key).

End-to-end example

  1. Connect to an ACK cluster using kubectl.

  2. Install the JSON processor jq.

  3. The following script demonstrates the complete end-to-end process, from an administrator initializing the resource environment and tenant credentials to a tenant independently managing the full lifecycle of Team keys.

    #!/usr/bin/env bash
    set -euo pipefail
    
    ADMIN_KEY="${ADMIN_KEY:?required}"
    # Two protocols are supported. This example uses the native E2B protocol endpoint: https://api.your.domain.com
    # To use the Agent Sandbox private protocol, replace BASE_URL with https://your.domain.com/kruise/api.
    BASE_URL="${BASE_URL:-https://api.your.domain.com}"
    TEAM_NAMESPACE="team-a"
    
    # 1. In the cluster, the administrator creates the Team's Namespace
    kubectl create ns "${TEAM_NAMESPACE}"
    
    # 2. The administrator creates a tenant key for team-a and records the returned plaintext key
    TENANT_KEY=$(curl -fsS -X POST \
      -H "X-API-KEY: ${ADMIN_KEY}" \
      -H "Content-Type: application/json" \
      -d "{\"name\":\"ci-runner\",\"teamName\":\"${TEAM_NAMESPACE}\"}" \
      "${BASE_URL}/api-keys" | jq -r '.key')
    
    # 3. The tenant lists their Team and existing Key
    curl -fsS -H "X-API-KEY: ${TENANT_KEY}" "${BASE_URL}/teams"
    curl -fsS -H "X-API-KEY: ${TENANT_KEY}" "${BASE_URL}/api-keys"
    
    # 4. The tenant creates a sub-key for their Team without the teamName field
    SUB_KEY_ID=$(curl -fsS -X POST \
      -H "X-API-KEY: ${TENANT_KEY}" \
      -H "Content-Type: application/json" \
      -d '{"name":"my-sub-key"}' \
      "${BASE_URL}/api-keys" | jq -r '.id')
    
    # 5. The tenant deletes their Team's sub Key
    curl -fsS -X DELETE \
      -H "X-API-KEY: ${TENANT_KEY}" \
      "${BASE_URL}/api-keys/${SUB_KEY_ID}"

API reference

List teams

Retrieves the Teams visible to the current user. Regular tenants can see only the Team to which they belong; administrators can see all Teams.

Request example:

curl -fsS \
  -H "X-API-KEY: ${E2B_API_KEY}" \
  "https://api.your.domain.com/teams"
import os
import requests

resp = requests.get(
    "https://api.your.domain.com/teams",
    headers={"X-API-KEY": os.environ["E2B_API_KEY"]},
    timeout=10,
)
try:
    resp.raise_for_status()
except requests.HTTPError:
    print(resp.text)
    raise
print(resp.json())

Expected output:

[
  {
    "teamID": "550e8400-e29b-41d4-a716-446655449999",
    "name": "admin",
    "apiKey": "",
    "isDefault": true
  }
]

The response body is a JSON array. The following table describes the fields in each item.

Field

Type

Description

teamID

string

The Team's UUID, used for display only.

name

string

The Team name, which is the same as the Kubernetes Namespace.

apiKey

string

This field always returns an empty string and is retained only for compatibility with the E2B SDK schema. To obtain a plaintext API key, use POST /api-keys to create one and save the returned value immediately.

isDefault

boolean

Whether this is the caller's default Team.

List API keys

Retrieves all API keys that belong to the Team of the current caller.

Request example:

curl -fsS \
  -H "X-API-KEY: ${E2B_API_KEY}" \
  "https://api.your.domain.com/api-keys"
import os
import requests

resp = requests.get(
    "https://api.your.domain.com/api-keys",
    headers={"X-API-KEY": os.environ["E2B_API_KEY"]},
    timeout=10,
)
try:
    resp.raise_for_status()
except requests.HTTPError:
    print(resp.text)
    raise
for key in resp.json():
    print(key["id"], key["name"], key["mask"])

Response fields:

Field

Type

Description

id

string

The UUID of the API key, which is used when deleting the key.

name

string

The human-readable name of the API key.

createdAt

string

The time when the API key was created.

createdBy.id

string

The UUID of the caller that created the API key.

lastUsed

string

The time when the API key was last used. The value is null if the key has never been used.

Create an API key

Creates a new API key. The key field in the response body contains the newly generated plaintext key. The plaintext key field is returned only once when the key is created and cannot be retrieved through any interface afterward. Save it immediately.

Note

Before running the example, make sure that the team-a namespace already exists. If the caller is a regular tenant, remove the teamName field from the request body.

Request example:

curl -fsS -X POST \
  -H "X-API-KEY: ${E2B_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{"name": "ci-runner", "teamName": "team-a"}' \
  "https://api.your.domain.com/api-keys"
import os
import requests

resp = requests.post(
    "https://api.your.domain.com/api-keys",
    headers={
        "X-API-KEY": os.environ["E2B_API_KEY"],
        "Content-Type": "application/json",
    },
    json={"name": "ci-runner", "teamName": "team-a"},
    timeout=10,
)
try:
    resp.raise_for_status()
except requests.HTTPError:
    print(resp.text)
    raise
created = resp.json()
# Immediately persist created["key"]- it cannot be retrieved again.
print(created["id"], created["key"])

Request body fields:

Field

Type

Required

Description

name

string

Yes

The human-readable name of the API key.

teamName

string

No

The name of the target Team. It defaults to the caller's own Team. Only an administrator can specify another Team, which must correspond to an existing Kubernetes Namespace. A regular tenant must omit this field.

Response fields:

Field

Type

Description

id

string

The UUID of the new API key, which is used for later deletion.

key

string

The plaintext API key, which is returned only once and must be saved immediately.

name

string

The API key name, which is the same as the value in the request body.

team.id

string

The UUID of the Team that actually owns the API key.

team.name

string

The name of the Team that actually owns the API key, that is, the corresponding Kubernetes Namespace. This is used to verify the caller's intent.

Delete an API key

Deletes a specified API key by its UUID. Regular tenants can delete only keys in their current Team. Administrators can delete any key except the admin API key. An attempt to delete the built-in admin API key returns 403 Forbidden.

Request example:

API_KEY_ID="<uuid-from-list-api-keys>"
curl -fsS -X DELETE \
  -H "X-API-KEY: ${E2B_API_KEY}" \
  "https://api.your.domain.com/api-keys/${API_KEY_ID}"
import os
import requests

api_key_id = "<uuid-from-list-api-keys>"
resp = requests.delete(
    f"https://api.your.domain.com/api-keys/{api_key_id}",
    headers={"X-API-KEY": os.environ["E2B_API_KEY"]},
    timeout=10,
)
# A successful request returns 204 No Content.
try:
    resp.raise_for_status()
except requests.HTTPError:
    print(resp.text)
    raise
Both invalid UUIDs and nonexistent UUIDs return 404 Not Found. The interface does not distinguish between these two cases.

Error codes

HTTP status code

Scenario

400

The request body is invalid (JSON parsing fails), or the target namespace does not exist.

401

The X-API-KEY request header is missing, or the API key is invalid.

403

A non-administrator performs a write operation on another Team, or attempts to delete the admin API key.

404

The API key with the specified UUID does not exist, or the path parameter is not a valid UUID string.

500

An internal server error occurs, for example, when a required field is missing, the Kubernetes API is unavailable, or persistent storage is unreachable.

The error response body is JSON and contains the code, message, and request_id fields to help locate issues:

{
  "code": 403,
  "message": "You are not allowed to create an API key for another team",
  "request_id": "c42c84d8-8420-4194-b48d-5bc5c8fe4ed6"
}