Skip to main content
This quickstart keeps the desktop owner outside the Function. The Function borrows the desktop once for the complete trajectory.

Set explicit application choices

Use one supported region selector for the Function and Sandbox. This example uses the public narrow selector us-west. You can use a Workspace-granted granular selector such as us-west-2 when your Modal Workspace supports it.

Define the placed Function

Keep your model call in this Function. The placeholder action below lets the example compile without a provider SDK.

Create and own the desktop

The owner waits for the Function result before it closes. Borrow cleanup runs first. Owner cleanup then terminates the desktop. Modal can report a provider-native runtime region such as us-west-2, us-west1, or westus3 for the public us-west selector.

Deploy the Function

Save the code in one module, then deploy it to the same explicit environment:
Invoking the Function and creating the Sandbox can incur Modal charges. Warm capacity remains off because min_containers=0 and this example creates no Sandbox pool. Use the maintained session-handoff example for cancellation, spawning, resolved configuration, and recovery handling.