Borrow an existing desktop for one deployed Modal Function trajectory.
Use a session handoff when a deployed Modal Function runs the complete screenshot, model, and action loop. The owner process keeps lifecycle ownership of the desktop.
Understand the ownership pattern
Your application creates the desktop.
The owner calls session_handle().
The owner passes the handle to a deployed Modal Function.
The Function enters one borrow_async() context for the complete trajectory.
The Function detaches when the borrow ends.
The owner terminates the desktop after the Function reaches a terminal result.
The handle contains routing identity. It is not a bearer credential. Do not log or publish it.
Replace application_model_call() with your application code. Use an async provider client so the Function event loop remains available.Set the same explicit region on the desktop configuration and the Function. The borrow checks function_region against the requested desktop region.
Deploy the Function
uv run modal deploy path/to/handoff_app.py
The deployed Function image must include modal-computer-use[modal]. The Function must have access to the Modal environment that owns the Sandbox.
Use one new run_id for each trajectory. Do not reuse a durably sealed run ID.
Keep one trajectory per desktop
The borrow takes an exclusive daemon trajectory lease. Concurrent work must use separate desktop handles.The Function leaves the desktop running when the borrow ends. Only the original owner terminates it.
A cancelled Function invocation does not reverse desktop effects that already occurred. Your application must reconcile an ambiguous result before it starts a new trajectory.
Use the session handoff example when a Modal Function needs one complete stateful trajectory. It shows dispatch, cancellation, and observation after result loss. The owner must reconcile an ambiguous outcome before it starts another trajectory.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Modal Computer Use","description":"Deploy and control a Linux desktop in a Modal Sandbox.","colors":{"primary":"#248713","light":"#7FEE63","dark":"#248713"},"logo":{"light":"https://mintcdn.com/modal-computer-use/U3YncLggMA24W1qr/logo/modal-computer-use-wordmark-light.png?fit=max\u0026auto=format\u0026n=U3YncLggMA24W1qr\u0026q=85\u0026s=943b5af5a43d50b39138b4e5edf2d97c","dark":"https://mintcdn.com/modal-computer-use/U3YncLggMA24W1qr/logo/modal-computer-use-wordmark-dark.png?fit=max\u0026auto=format\u0026n=U3YncLggMA24W1qr\u0026q=85\u0026s=bb97fc01370de2e9fec2d07ec9abfe10"},"favicon":"https://mintcdn.com/modal-computer-use/3wQYz05ZptY4tQnA/favicon.png?fit=max\u0026auto=format\u0026n=3wQYz05ZptY4tQnA\u0026q=85\u0026s=f1678b886ff6b5dd229b7c6eb8962495","background":{"color":{"dark":"#141614"}},"navbar":{"primary":{"type":"github","href":"https://github.com/ashtonchew/modal-computer-use"}},"footer":{"socials":{"github":"https://github.com/ashtonchew/modal-computer-use","x":"https://x.com/ashtonchew"},"links":[{"header":"Project","items":[{"label":"GitHub","href":"https://github.com/ashtonchew/modal-computer-use"},{"label":"PyPI","href":"https://pypi.org/project/modal-computer-use"},{"label":"Releases","href":"https://github.com/ashtonchew/modal-computer-use/releases"}]},{"header":"Support","items":[{"label":"Issues","href":"https://github.com/ashtonchew/modal-computer-use/issues"},{"label":"Security","href":"https://github.com/ashtonchew/modal-computer-use/security/policy"}]}]},"fonts":{"family":"Geist"},"icons":{"library":"tabler"},"styling":{"eyebrows":"breadcrumbs","codeblocks":"system","latex":false},"contextual":{"options":["copy","view","chatgpt","claude"],"display":"header"},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"modal-computer-use","hasAudioNarration":false,"actualSubdomain":"modal-computer-use","customDomains":[],"gitSource":{"type":"github","owner":"ashtonchew","repo":"modal-computer-use-docs","deployBranch":"main","contentDirectory":"","isPrivate":false,"mountPath":"","label":""},"entitlements":{"AI_CHAT":{"status":"DISABLED"}},"buildId":"6a9c759a10ab928b389deeb0","clientVersion":"0.0.4286","searchFilterCounts":[{"language":"default","tag":"Documentation","count":37},{"language":"default","tag":"Desktop workflows","count":13},{"language":"default","tag":"Benchmarks","count":12},{"language":"default","tag":"Deployment and operations","count":12},{"language":"default","tag":"API Reference","count":12},{"language":"default","tag":"Python SDK","count":10},{"language":"default","tag":"Results and evidence","count":8},{"language":"default","tag":"Getting started","count":8},{"language":"default","tag":"Run and reproduce","count":4},{"language":"default","tag":"Model integrations","count":4}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"site-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"treatment","enabled":true,"payload":{"type":"string","value":"treatment"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"wildcard-email-auth","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":true},"customCss":[{"filePath":"style.css","content":"#pagination{display:grid;grid-template-columns:repeat(2, minmax(0, 1fr));gap:1rem}#pagination a{box-sizing:border-box;width:100%;min-height:4.5rem;margin-left:0;padding:0.75rem 1rem;border:1px solid rgb(var(--gray-200) / 0.7);border-radius:0.75rem;background:transparent;transition:border-color 150ms ease-out}#pagination a:hover{border-color:rgb(var(--gray-300))}#pagination a[rel=\"next\"]{justify-content:flex-end;text-align:right}#pagination a[rel=\"next\"]{grid-column:2}.dark #pagination a{border-color:rgb(var(--gray-800) / 0.7)}.dark #pagination a:hover{border-color:rgb(var(--gray-700))}@media (max-width: 63.999rem){#pagination{grid-template-columns:minmax(0, 1fr)}#pagination a[rel=\"next\"]{grid-column:1}}.action-frame-results th,.action-frame-results td{min-width:0!important}"}]}
{"page":{"pagePath":"v1/build/session-handoff","slug":"/v1/build/session-handoff","pageMetadata":{"title":"Hand a desktop to a Modal Function","sidebarTitle":"Session handoff","description":"Borrow an existing desktop for one deployed Modal Function trajectory.","href":"/v1/build/session-handoff"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Borrow an existing desktop for one deployed Modal Function trajectory.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,..._provideComponents(),...props.components},{CodeBlock,Heading,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(_components.p,{children:`Use a session handoff when a deployed Modal Function runs the complete screenshot, model, and action loop. The owner process keeps lifecycle ownership of the desktop.`}),`\n`,_jsx(Heading,{level:`2`,id:`understand-the-ownership-pattern`,children:`Understand the ownership pattern`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsx(_components.li,{children:`Your application creates the desktop.`}),`\n`,_jsxs(_components.li,{children:[`The owner calls `,_jsx(_components.code,{children:`session_handle()`}),`.`]}),`\n`,_jsx(_components.li,{children:`The owner passes the handle to a deployed Modal Function.`}),`\n`,_jsxs(_components.li,{children:[`The Function enters one `,_jsx(_components.code,{children:`borrow_async()`}),` context for the complete trajectory.`]}),`\n`,_jsx(_components.li,{children:`The Function detaches when the borrow ends.`}),`\n`,_jsx(_components.li,{children:`The owner terminates the desktop after the Function reaches a terminal result.`}),`\n`]}),`\n`,_jsx(_components.p,{children:`The handle contains routing identity. It is not a bearer credential. Do not log or publish it.`}),`\n`,_jsx(Heading,{level:`2`,id:`define-the-deployed-function`,children:`Define the deployed Function`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`31`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`31`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` modal`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` modal_computer_use `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ComputerSessionHandle`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`function_region `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"us-west\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`app `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` modal.App(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"computer-use-function-handoff\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`image `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` modal.Image.debian_slim().pip_install(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"modal-computer-use[modal]\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`@app.function`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` image`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`image,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` region`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`function_region,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` retries`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` min_containers`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` max_containers`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`4`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` timeout`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`900`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`async`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` run_trajectory`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` handle`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: ComputerSessionHandle,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` task`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` run_id`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) -> dict[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` async`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` handle.borrow_async(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` run_id`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`run_id,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` function_region`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`function_region,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` computer:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` _ `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` range`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`3`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` screenshot `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` computer.screenshots.full()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` action `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` application_model_call(task, screenshot)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` computer.actions.run([action])`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"status\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"succeeded\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Replace `,_jsx(_components.code,{children:`application_model_call()`}),` with your application code. Use an async provider client so the Function event loop remains available.`]}),`\n`,_jsxs(_components.p,{children:[`Set the same explicit region on the desktop configuration and the Function. The borrow checks `,_jsx(_components.code,{children:`function_region`}),` against the requested desktop region.`]}),`\n`,_jsx(Heading,{level:`2`,id:`deploy-the-function`,children:`Deploy the Function`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`uv`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` run`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` modal`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` deploy`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` path/to/handoff_app.py`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`The deployed Function image must include `,_jsx(_components.code,{children:`modal-computer-use[modal]`}),`. The Function must have access to the Modal environment that owns the Sandbox.`]}),`\n`,_jsx(Heading,{level:`2`,id:`invoke-the-function-from-the-owner`,children:`Invoke the Function from the owner`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`23`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`23`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` uuid`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` modal`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` modal_computer_use `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ComputerConfig, ComputerSandbox`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`function_region `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"us-west\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`app_name `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"computer-use-function-handoff\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`deployed `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` modal.Function.from_name(app_name, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"run_trajectory\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`config `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ComputerConfig(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` ingress`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"attested-tunnel\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` runtime`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"modal_environment\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"main\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"modal_region\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: function_region,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`with`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ComputerSandbox.create(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`config`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`config, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`app_name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`app_name) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` owner:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` handle `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` owner.session_handle()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` run_id `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"trajectory_`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`uuid.uuid4().hex`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` result `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` deployed.remote(handle, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"replace with your task\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, run_id)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(result[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"status\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`])`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Use one new `,_jsx(_components.code,{children:`run_id`}),` for each trajectory. Do not reuse a durably sealed run ID.`]}),`\n`,_jsx(Heading,{level:`2`,id:`keep-one-trajectory-per-desktop`,children:`Keep one trajectory per desktop`}),`\n`,_jsx(_components.p,{children:`The borrow takes an exclusive daemon trajectory lease. Concurrent work must use separate desktop handles.`}),`\n`,_jsx(_components.p,{children:`The Function leaves the desktop running when the borrow ends. Only the original owner terminates it.`}),`\n`,_jsx(Warning,{children:_jsx(_components.p,{children:`A cancelled Function invocation does not reverse desktop effects that already occurred. Your application must reconcile an ambiguous result before it starts a new trajectory.`})}),`\n`,_jsxs(_components.p,{children:[`Use the `,_jsx(_components.a,{href:`https://github.com/ashtonchew/modal-computer-use/blob/main/examples/modal_function_session_handoff.py`,children:`session handoff example`}),` when a Modal Function needs one complete stateful trajectory. It shows dispatch, cancellation, and observation after result loss. The owner must reconcile an ambiguous outcome before it starts another trajectory.`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"codeStyling":"system","config":{},"pageMetadata":{"title":"Hand a desktop to a Modal Function","sidebarTitle":"Session handoff","description":"Borrow an existing desktop for one deployed Modal Function trajectory.","href":"/v1/build/session-handoff"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Understand the ownership pattern","slug":"understand-the-ownership-pattern","depth":2,"children":[]},{"title":"Define the deployed Function","slug":"define-the-deployed-function","depth":2,"children":[]},{"title":"Deploy the Function","slug":"deploy-the-function","depth":2,"children":[]},{"title":"Invoke the Function from the owner","slug":"invoke-the-function-from-the-owner","depth":2,"children":[]},{"title":"Keep one trajectory per desktop","slug":"keep-one-trajectory-per-desktop","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":["/_mintlify/custom/modal-computer-use/afedbf24fbf1ce4f/table-keyboard-scroll.js"],"subdomain":"modal-computer-use","siteName":"Modal Computer Use","title":"Hand a desktop to a Modal Function - Modal Computer Use","navMaps":{"firstHrefInVersion":{"2.x":{"href":"/build/session-handoff","matchLevel":1},"1.x":{"href":"/v1/build/session-handoff","matchLevel":0}},"firstHrefInLanguage":{}},"lastModified":"2026-08-11T01:51:58.787Z","originalFileLocation":"v1/build/session-handoff.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Borrow an existing desktop for one deployed Modal Function trajectory.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Modal Computer Use\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/modal-computer-use/QIAzi0owsS6Rkve0/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/modal-computer-use/QIAzi0owsS6Rkve0/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/modal-computer-use/QIAzi0owsS6Rkve0/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/modal-computer-use/QIAzi0owsS6Rkve0/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/modal-computer-use/QIAzi0owsS6Rkve0/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/modal-computer-use/QIAzi0owsS6Rkve0/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/modal-computer-use/QIAzi0owsS6Rkve0/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/modal-computer-use/QIAzi0owsS6Rkve0/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/modal-computer-use/QIAzi0owsS6Rkve0/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Hand a desktop to a Modal Function - Modal Computer Use\">\u003cmeta data-mint-head property=\"og:description\" content=\"Borrow an existing desktop for one deployed Modal Function trajectory.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Modal Computer Use\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://modal-computer-use.mintlify.app/v1/build/session-handoff\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://modal-computer-use.mintlify.site/_mintlify/api/og/v2?division=Desktop+workflows\u0026amp;title=Hand+a+desktop+to+a+Modal+Function\u0026amp;description=Borrow+an+existing+desktop+for+one+deployed+Modal+Function+trajectory.\u0026amp;theme=b7d7aff4163f59c6d290186a\u0026amp;signature=d7d6ee0a96e1f18758bd613a0d44a19798e13811631abd559f3e7350f20ace57\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Hand a desktop to a Modal Function - Modal Computer Use\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Borrow an existing desktop for one deployed Modal Function trajectory.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://modal-computer-use.mintlify.site/_mintlify/api/og/v2?division=Desktop+workflows\u0026amp;title=Hand+a+desktop+to+a+Modal+Function\u0026amp;description=Borrow+an+existing+desktop+for+one+deployed+Modal+Function+trajectory.\u0026amp;theme=b7d7aff4163f59c6d290186a\u0026amp;signature=d7d6ee0a96e1f18758bd613a0d44a19798e13811631abd559f3e7350f20ace57\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/modal-computer-use/QIAzi0owsS6Rkve0/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Modal Computer Use\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#248713\">\u003clink data-mint-head rel=\"canonical\" href=\"https://modal-computer-use.mintlify.app/v1/build/session-handoff\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/v1/build/session-handoff.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://modal-computer-use.mintlify.app/#organization\",\"name\":\"Modal Computer Use\",\"url\":\"https://modal-computer-use.mintlify.app\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/modal-computer-use/U3YncLggMA24W1qr/logo/modal-computer-use-wordmark-light.png?fit=max\u0026auto=format\u0026n=U3YncLggMA24W1qr\u0026q=85\u0026s=943b5af5a43d50b39138b4e5edf2d97c\"}},{\"@type\":\"WebSite\",\"@id\":\"https://modal-computer-use.mintlify.app#website\",\"name\":\"Modal Computer Use\",\"url\":\"https://modal-computer-use.mintlify.app\",\"publisher\":{\"@id\":\"https://modal-computer-use.mintlify.app/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://modal-computer-use.mintlify.app/v1/build/session-handoff#webpage\",\"url\":\"https://modal-computer-use.mintlify.app/v1/build/session-handoff\",\"name\":\"Hand a desktop to a Modal Function\",\"description\":\"Borrow an existing desktop for one deployed Modal Function trajectory.\",\"dateModified\":\"2026-08-11T01:51:58.787Z\",\"isPartOf\":{\"@id\":\"https://modal-computer-use.mintlify.app#website\"},\"breadcrumb\":{\"@id\":\"https://modal-computer-use.mintlify.app/v1/build/session-handoff#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://modal-computer-use.mintlify.app/v1/build/session-handoff#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Desktop workflows\",\"item\":\"https://modal-computer-use.mintlify.app/v1/build/create-and-attach\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hand a desktop to a Modal Function\",\"item\":\"https://modal-computer-use.mintlify.app/v1/build/session-handoff\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://modal-computer-use.mintlify.app/v1/build/session-handoff#article\",\"headline\":\"Hand a desktop to a Modal Function\",\"name\":\"Hand a desktop to a Modal Function\",\"description\":\"Borrow an existing desktop for one deployed Modal Function trajectory.\",\"url\":\"https://modal-computer-use.mintlify.app/v1/build/session-handoff\",\"mainEntityOfPage\":{\"@id\":\"https://modal-computer-use.mintlify.app/v1/build/session-handoff#webpage\"},\"dateModified\":\"2026-08-11T01:51:58.787Z\",\"publisher\":{\"@id\":\"https://modal-computer-use.mintlify.app/#organization\"},\"isPartOf\":{\"@id\":\"https://modal-computer-use.mintlify.app#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Modal Computer Use\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Modal Computer Use\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/v1/build/session-handoff.md","siteName":"Modal Computer Use","nav":{"global":null,"versions":[{"version":"2.x","default":true,"tag":"Latest","pages":[{"title":"2.x","href":"/build/session-handoff"}]},{"version":"1.x","tag":"Previous","tabs":[{"tab":"Documentation","icon":"book","groups":[{"group":"Getting started","pages":[{"title":"Control a Linux desktop on Modal","sidebarTitle":"Home","href":"/v1"},{"title":"Install Modal Computer Use","sidebarTitle":"Installation","href":"/v1/start/installation"},{"title":"Create your first desktop","sidebarTitle":"Quickstart","href":"/v1/start/quickstart"},{"title":"Choose an example","sidebarTitle":"Examples","href":"/v1/start/examples"}]},{"group":"Desktop workflows","pages":[{"title":"Create and attach to desktops","sidebarTitle":"Create and attach","href":"/v1/build/create-and-attach"},{"title":"Automate a browser","sidebarTitle":"Browser automation","href":"/v1/build/browser-automation"},{"title":"Run action batches","sidebarTitle":"Action batches","href":"/v1/build/action-batches"},{"title":"Capture screenshots and recordings","sidebarTitle":"Screenshots and recordings","href":"/v1/build/screenshots-recordings"},{"title":"Store and persist artifacts","sidebarTitle":"Artifacts and storage","description":"Read, write, download, and persist files under the artifact root.","href":"/v1/build/artifacts-storage"},{"title":"Hand a desktop to a Modal Function","sidebarTitle":"Session handoff","href":"/v1/build/session-handoff"}]},{"group":"Model integrations","pages":[{"title":"Run an OpenAI computer loop","sidebarTitle":"OpenAI","description":"Connect the OpenAI Responses API computer tool to a Modal desktop.","href":"/v1/integrate/openai"},{"title":"Run an Anthropic computer loop","sidebarTitle":"Anthropic","href":"/v1/integrate/anthropic"}]},{"group":"Deployment and operations","pages":[{"title":"Deploy a Modal desktop","sidebarTitle":"Deploy","href":"/v1/operate/deploy"},{"title":"Configure a desktop","sidebarTitle":"Configure","href":"/v1/operate/configure"},{"title":"Keep warm desktop capacity","sidebarTitle":"Warm capacity","href":"/v1/operate/warm-capacity"},{"title":"Reduce desktop loop latency","sidebarTitle":"Performance","href":"/v1/operate/performance"},{"title":"Secure a desktop deployment","sidebarTitle":"Security","href":"/v1/operate/security"},{"title":"Troubleshoot a desktop","sidebarTitle":"Troubleshooting","href":"/v1/operate/troubleshooting"}]}]},{"tab":"Benchmarks","icon":"stopwatch","pages":[{"title":"Benchmarks","href":"/v1/benchmarks/overview"}]},{"tab":"API Reference","icon":"code","pages":[{"title":"API Reference","href":"/v1/reference/overview"}]}]}]},"basePath":"","title":"Hand a desktop to a Modal Function - Modal Computer Use","deploymentId":"dpl_G6E2ur2Zjq51xGTVZPSFXsWoTxCu","buildId":"dpl_G6E2ur2Zjq51xGTVZPSFXsWoTxCu","dynamics":[],"chunks":[]}