ComputerSandbox.create() for a new synchronous desktop. Use AsyncComputerSandbox.create() in an asyncio application.
Install the Modal extra
Create and own a desktop
8080. Modal waits for TCP readiness. The default create call also waits for /readyz before it yields the desktop.
/healthz proves that the daemon process is alive. /readyz also checks the desktop dependencies.
The created context owns the Sandbox. It terminates the Sandbox and closes the connection on exit.
Attach without taking ownership
Use exactly one selector:sandbox_id, name, run_id, or direct base_url. A direct URL does not resolve a Modal Sandbox.
An attached context closes its connection on exit. It does not terminate the remote owner’s Sandbox.
Use attach_or_create(name=...) when one app needs one compatible named desktop. Modal enforces name uniqueness within the App. The SDK checks the app and configuration tags before reuse.
Select ingress
Keep
attested-tunnel unless your deployment has a measured or policy requirement.
Hand a session to a Modal Function
Use a deployed Modal Function for a repeated model and desktop trajectory. Create the desktop with an explicitruntime.modal_region. Use attested-tunnel or connect ingress. Keep VNC off or view-only.
- Create the desktop in the owner process.
- Call
session_handle()on the owner. - Pass the handle to the deployed Function.
- Enter one
borrow_async()context for the complete trajectory. - Wait for the Function outcome.
- Terminate the desktop in the owner process.
borrow_async(function_region=...).
Use retries=0 for the stateful Function. A platform retry still does not make a GUI trajectory exactly once.
The session handoff example shows how an owner lends one desktop to a deployed Function. Use it when the Function needs a complete stateful trajectory. The owner remains responsible for lifetime and ambiguous outcomes.
Clean up stale desktops
Inspect a cleanup plan before you terminate anything:dry_run=False only after you review the plan. The manager skips a Sandbox when it cannot prove the creation time or app ownership.
