This release is a pre-release and may not be stable for production use.
Azure Container Apps Sandbox Client Library for Python
⚠️ Preview — This SDK is in preview. The API surface may change without notice.
Data-plane SDK for ACA Sandboxes.
Isolated MicroVMs
Secure, isolated compute environments with sub-second startup.
- Hardware-isolated microVM boundary — fully separated from host, platform, and other sandboxes
- Snapshot-based suspend/resume preserving full memory and disk state across sessions
- Per-sandbox network egress policy with deny-by-default posture for untrusted code
What you can build
- Traditional Apps. Lift-and-shift workloads that need stateful compute, custom kernels, or per-tenant isolation without rewriting.
- AI Apps & Agents. Persistent, isolated workspaces that survive across task boundaries. Suspend between turns, resume with full context.
- Code execution. Run untrusted code in seconds with strong isolation. Capture state with snapshots, replay deterministically.
- Dev environments. Per-user compute that scales from zero to hundreds on demand and preserves state across sessions.
- Many more… CI runners, browser automation, data prep, reproducible experiments — anywhere a fast, isolated VM helps.
Installation
pip install azure-containerapps-sandbox
Quick start
Provision the resource group and sandbox group separately before using this SDK,
and grant your calling identity the Container Apps SandboxGroup Data Owner
role on the group or its parent resource group. Supply the existing subscription
ID, resource group, sandbox group name, and regional endpoint below.
SandboxGroupManagementClient (sync and async) and the ARM SandboxGroup model
have been removed; this package does not create, configure, or delete sandbox
groups.
from azure.identity import DefaultAzureCredential
from azure.containerapps.sandbox import (
SandboxGroupClient,
endpoint_for_region,
)
credential = DefaultAzureCredential()
subscription_id = "<your-subscription-id>"
resource_group = "my-rg"
sandbox_group = "my-sandbox-group"
region = "eastus2"
# 1. Connect to an existing sandbox group and create a sandbox
client = SandboxGroupClient(
endpoint_for_region(region), credential,
subscription_id=subscription_id,
resource_group=resource_group,
sandbox_group=sandbox_group,
)
sandbox = client.create_sandbox(disk="ubuntu")
# 2. Run a command
result = sandbox.exec("echo hello world && uname -a")
print(result.stdout)
# 3. Delete the sandbox; keep the separately provisioned group
sandbox.delete()
client.close()
create_sandbox() sends the create request and returns a SandboxClient on
HTTP 201 Created, without issuing follow-up GETs or creating a poller.
The async equivalent is sandbox = await client.create_sandbox(...).
The existing begin_create_sandbox(...).result() (or its async equivalent)
remains available to explicitly wait for the sandbox to reach Running.
Authentication
Uses DefaultAzureCredential from azure-identity, which automatically
picks up az login, managed identity, environment variables, etc.
Import container images
Sync and async create_disk_image and begin_create_disk_image import registry
images using PUT /diskimages/v2. Image references (including tags, digests and
registry ports) are sent unchanged. create_disk_image returns immediately;
begin_create_disk_image polls the disk image with GET until it is ready.
from azure.containerapps.sandbox import RegistryCredentials
image = client.begin_create_disk_image("docker.io/library/alpine:latest", name="alpine").result()
private_image = client.begin_create_disk_image(
"example.azurecr.io/team/app:v1",
registry_credentials=RegistryCredentials(username="<user>", token="<token>"),
).result()
identity_image = client.begin_create_disk_image(
"example.azurecr.io/team/app:v1",
managed_identity_client_id="<user-assigned-identity-client-id>",
).result()
Omit both authentication options for anonymous pulls. Credentials require both a
nonempty username and token and cannot be combined with managed identity.
managed_identity_client_id="system" selects the sandbox group's
system-assigned identity (case-insensitive). A user-assigned identity must be an
identity client ID, not an ARM resource ID. Configure the identity on the group
separately and grant it registry pull permissions. The SDK passes the supplied
identity selector directly to the data plane and does not look up identities
through ARM.
Breaking change: replace managed_identity_resource_id with
managed_identity_client_id; for user-assigned identities, supply the client ID
rather than the resource ID.
Breaking change: disk-image create methods no longer accept entrypoint or
cmd, including via **kwargs. Configure command overrides when creating the
sandbox container instead. Disk-image response image.entrypoint and
image.cmd metadata is still available.
For aio clients, await the create/begin calls and the poller's result().
Complete egress policies
Use sandbox.get_egress_policy() and sandbox.set_egress_policy(policy) as the
primary entry points. EgressPolicy exposes http: EgressHttpPolicy,
tds: EgressTdsPolicy, and transport_rules: EgressTransportPolicy, including
forward proxies, hooks, database credentials, routing, inspection, enforcement,
and validation warnings. These public models are imported from
azure.containerapps.sandbox, not _generated.
Fetch the whole policy before editing an existing section, then write it back
to preserve the other sections. For structured policies, change
policy.http.default_action, not the legacy flat policy.default_action.
An HTTP default does not configure TDS or TCP/UDP defaults.
set_egress_default() has been removed from both sync and async clients.
See the full policy examples and model reference.
TCP port forwarding
Before cleanup, reuse sandbox above with the group client's endpoint set to the
regional managementEndpoint supplied by your separate provisioning workflow.
For an HTTP server on port 8080 in the default container:
import sys
with sandbox.start_port_forward(8080) as tunnel:
tunnel.write(b"GET / HTTP/1.1\r\nHost: localhost:8080\r\nConnection: close\r\n\r\n")
while (chunk := tunnel.read(timeout=30)) is not None:
sys.stdout.buffer.write(chunk)
with closes only the tunnel. For aio, use async credentials/clients and
async with await sandbox.start_port_forward(...), await tunnel.write(...),
and async for chunk in tunnel. Read timeout or async task cancellation closes only
the tunnel; asyncio.timeout can bound authentication and I/O. Connect/handshake
timeouts do not bound token acquisition.
See data-plane authorization and protocol requirements.
Sandbox group metrics
Group-level metrics are always enabled. To opt into per-sandbox metrics, configure
enableDetailedMetrics on the sandbox group through your separate provisioning
workflow. This Python data-plane SDK does not manage that setting.
Port access control
Ports default to anonymous access (accessible without authentication),
matching the portal. Integer entries such as ports=[8080] and
sandbox.update_ports([8080]) use this default, as does sandbox.add_port(8080).
Missing/empty auth, anonymous=False without a nonempty email, and disabled
Entra providers also default to anonymous. Enabled Entra policies are preserved.
To require authentication, pass email="user@contoso.com" to add_port, or
use AddPortRequest with auth=PortAuthConfig(entra_id=PortAuthEntraId(enabled=True, emails=[...]))
when creating or updating ports. The same behavior applies to async clients.
Restrict which inbound client IPs can reach a port with a source-IP
allow/deny policy. Rules match by CIDR range — the lowest priority is
evaluated first, and default_action decides traffic that matches no rule.
from azure.containerapps.sandbox import (
PortIpAccessControl,
PortIpAccessControlRule,
)
# Allow only an internal range; deny everything else.
acl = PortIpAccessControl(
default_action="Deny",
rules=[
PortIpAccessControlRule(
name="office",
action="Allow",
priority=10,
source_cidrs=["10.0.0.0/8"],
),
],
)
# Open a port with the policy on an existing sandbox.
sandbox.add_port(8443, ip_access_control=acl)
Set the same policy at sandbox creation by passing AddPortRequest to
ports= (it also works with sandbox.update_ports([...])):
from azure.containerapps.sandbox import AddPortRequest
sandbox = client.begin_create_sandbox(
disk="ubuntu",
ports=[AddPortRequest(port=8443, ip_access_control=acl)],
).result()
Read the effective policy back from a response port via
SandboxPort.ip_access_control. The async aio clients accept the identical
ip_access_control keyword.
The policy is validated client-side before it is sent; an invalid one raises
ValueError. Constraints mirror the service:
- At most 10 rules, each with 1–10 source CIDRs.
- Each CIDR must be network-aligned (host bits zero) —
10.0.0.0/8is valid,10.0.0.5/8is rejected. priorityis 0–1000; names and priorities must be unique (names case-insensitive). Lower priority is evaluated first.
Metadata
Release files for azure-containerapps-sandbox 1.0.0b1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| azure_containerapps_sandbox-1.0.0b1.tar.gz | 205.3 kB | Without provenance | Details for azure_containerapps_sandbox-1.0.0b1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| azure_containerapps_sandbox-1.0.0b1-py3-none-any.whl | Python 3 | none | any | Details for azure_containerapps_sandbox-1.0.0b1-py3-none-any.whl |
Total release size: 441.5 kB
Release files / azure_containerapps_sandbox-1.0.0b1.tar.gz
| Download URL | azure_containerapps_sandbox-1.0.0b1.tar.gz |
|---|---|
| Size | 205.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4947bf6faa1c40a546f42d6b5ee6bbe17151c9470a62da8285ab7bb122992455
|
|
BLAKE2b-256 checksum How to use checksums |
282487afd6cfe1a0f2585f1d42d5c932e04518c60a990e570a6cf0612f1281c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / azure_containerapps_sandbox-1.0.0b1-py3-none-any.whl
| Download URL | azure_containerapps_sandbox-1.0.0b1-py3-none-any.whl |
|---|---|
| Size | 236.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fee08931e201aae54d75cc31558c66d5d7e7b15123b37c4cf074b7085f498a93
|
|
BLAKE2b-256 checksum How to use checksums |
2e0a2fb39fc131af42903d98809e144002a467ae0db986486861d58cd4cd5d5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Security for azure-containerapps-sandbox 1.0.0b1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.