Cua Docs

SDK reference

Python and TypeScript packages, constructors, methods, results, and errors for the typed Cua Driver SDK.

Packages#

RuntimePackageImport
Pythoncua-driverfrom cua_driver import CuaDriver
Node.js / TypeScript@trycua/cua-driverimport { CuaDriver } from "@trycua/cua-driver"

Both packages are generated from the same Rust and UniFFI contract. Methods are asynchronous. Python uses snake_case; TypeScript uses camelCase.

Constructors#

PythonTypeScriptBehavior
CuaDriver.create(options=None)CuaDriver.create(options?)Creates the primary same-process runtime. No daemon, executable, or IPC is required.
CuaDriver.connect(socket_path=None)CuaDriver.connect(socketPath?)Connects the same typed surface to a daemon. This is a compatibility and app-hosting path.

DriverOptions currently contains claude_code_compatibility / claudeCodeCompatibility, which defaults to false.

execution_mode() / executionMode() reports the generated DriverExecutionMode value. The current enum variants are Embedded for the same-process runtime and Daemon for a socket-backed connection.

Lifecycle and metadata#

PythonTypeScriptResult
metadata()metadata()Driver version, protocol version, and platform metadata
execution_mode()executionMode()DriverExecutionMode
is_available()isAvailable()Whether the runtime can serve calls
shutdown()shutdown()Stops admission and awaits admitted work

In TypeScript, shutdown() and uniffiDestroy() have separate jobs: shutdown() closes runtime admission and awaits admitted operations; uniffiDestroy() immediately frees the generated UniFFI object handle. JavaScript's FinalizationRegistry is only a nondeterministic fallback, so orderly applications call both, in that order. Python finalization releases its handle automatically, but applications must still await shutdown().

Session methods#

PythonTypeScriptInput
start_sessionstartSessionStartSessionInput
get_session_stategetSessionStateGetSessionStateInput
escalate_sessionescalateSessionEscalateSessionInput
end_sessionendSessionEndSessionInput

StartSessionInput.capture_scope / captureScope accepts AUTO, WINDOW, or DESKTOP. Capture scope is immutable for a live session. AUTO requires an explicit escalation before desktop tools are enabled.

Typed desktop methods#

PythonTypeScriptInput
get_desktop_stategetDesktopStateGetDesktopStateInput
get_screen_sizegetScreenSizeGetScreenSizeInput
get_cursor_positiongetCursorPositionGetCursorPositionInput
move_cursormoveCursorMoveCursorInput
clickclickClickInput
dragdragDragInput
scrollscrollScrollInput
type_texttypeTextTypeTextInput
press_keypressKeyPressKeyInput
hotkeyhotkeyHotkeyInput

Use list_tools_json() / listToolsJson() and call_tool() / callTool() for the generic, platform-extensible tool surface. Prefer typed methods when one is available.

ToolResult#

Desktop methods return ToolResult.

Python fieldTypeScript fieldMeaning
texttextHuman-readable result text
imagesimagesReturned images and MIME types
structured_jsonstructuredJsonStructured platform result
is_errorisErrorWhether the tool reported failure
error_codeerrorCodeStable tool error code, when present
verifiedverifiedWhether post-action verification succeeded
degradeddegradedWhether a reduced-capability path was used
raw_jsonrawJsonComplete extensible result envelope

Errors#

The generated DriverError variants are:

  • Configuration
  • InvalidArguments
  • Transport
  • Protocol
  • Tool
  • Shutdown

Tool-level failures may also arrive as ToolResult.is_error / isError. Inspect the result before consuming images or structured fields.

See MCP tools for the agent-facing tool catalog and SDK, MCP, and process hosting for the architecture boundary.