Async snippets with top-level
await run inside an async function or a notebook
that supports it. For a standalone script, use the asyncio.run(main()) structure
from Your first sandbox.Fail a sandbox workflow on a nonzero exit
A nonzero command exit returns a result. Callingrun_workflow() below raises
inside the context, discards unsaved changes, and closes the VM.
- Sync
- Async
Advanced: a command returned a nonzero exit code
This is a process result, sorun() returns it without raising FailedOperationError.
The example uses disposable execution and leaves the session image unchanged.
- Sync
- Async
Advanced: select a late result
A completed operation retains its original parent. If local navigation or another operation changes the selected position, committing the result saves a sibling without selecting it. To save and select that result, give it a local branch name:- Sync
- Async
Waiting failed, timed out, or was cancelled
Operation.wait() attempts cancellation when waiting raises and keeps the original
exception. A cancelled operation raises InterruptedError; an operation with no
successful result raises FailedOperationError. Client transport errors can also
propagate. Cleanup is best effort: retain the operation UUID if you need to inspect
its server status afterward.
A subprocess wait timeout does not itself terminate the whole operation. Use its
operation’s signal() or cancel(), or leave the operation context to shut it down.
See Advanced: control a running sandbox and SDK exceptions.
Advanced: catch an operation failure
If the server cannot complete the operation, the SDK raisesFailedOperationError
and leaves history unchanged. Keep the operation UUID to investigate the failure:
- Sync
- Async