AsyncComputerUse
class AsyncComputerUse()
デスクトップ環境と対話するためのコンピューター操作(Computer Use)機能。
サンドボックス(Daytonaが管理する隔離された一時的な実行環境)内でのデスクトップ操作自動化のために、マウス、キーボード、スクリーンショット、ディスプレイの各操作にアクセスできます。
属性:
mouseAsyncMouse - マウス操作インターフェース。keyboardAsyncKeyboard - キーボード操作インターフェース。screenshotAsyncScreenshot - スクリーンショット操作インターフェース。displayAsyncDisplay - ディスプレイ操作インターフェース。
AsyncComputerUse.start
@intercept_errors(message_prefix="Failed to start computer use: ")
async def start() -> ComputerUseStartResponse
すべてのコンピューター操作プロセス(Xvfb、xfce4、x11vnc、novnc)を起動します。
戻り値:
ComputerUseStartResponse- コンピューター操作の起動レスポンス。
例:
result = await sandbox.computer_use.start()
print("Computer use processes started:", result.message)
AsyncComputerUse.stop
@intercept_errors(message_prefix="Failed to stop computer use: ")
async def stop() -> ComputerUseStopResponse
すべてのコンピューター操作プロセスを停止します。
戻り値:
ComputerUseStopResponse- コンピューター操作の停止レスポンス。
例:
result = await sandbox.computer_use.stop()
print("Computer use processes stopped:", result.message)
AsyncComputerUse.get_status
@intercept_errors(message_prefix="Failed to get computer use status: ")
async def get_status() -> ComputerUseStatusResponse
すべてのコンピューター操作プロセスのステータスを取得します。
戻り値:
ComputerUseStatusResponse- すべてのVNCデスクトッププロセスに関するステータス情報。
例:
response = await sandbox.computer_use.get_status()
print("Computer use status:", response.status)
AsyncComputerUse.get_process_status
@intercept_errors(message_prefix="Failed to get process status: ")
async def get_process_status(process_name: str) -> ProcessStatusResponse
特定のVNCプロセスのステータスを取得します。
引数:
process_namestr - 確認するプロセス名。
戻り値:
ProcessStatusResponse- 指定したプロセスに関するステータス情報。
例:
xvfb_status = await sandbox.computer_use.get_process_status("xvfb")
no_vnc_status = await sandbox.computer_use.get_process_status("novnc")
AsyncComputerUse.restart_process
@intercept_errors(message_prefix="Failed to restart process: ")
async def restart_process(process_name: str) -> ProcessRestartResponse
特定のVNCプロセスを再起動します。
引数:
process_namestr - 再起動するプロセス名。
戻り値:
ProcessRestartResponse- プロセス再起動のレスポンス。
例:
result = await sandbox.computer_use.restart_process("xfce4")
print("XFCE4 process restarted:", result.message)
AsyncComputerUse.get_process_logs
@intercept_errors(message_prefix="Failed to get process logs: ")
async def get_process_logs(process_name: str) -> ProcessLogsResponse
特定のVNCプロセスのログを取得します。
引数:
process_namestr - ログを取得するプロセス名。
戻り値:
ProcessLogsResponse- プロセスのログ。
例:
logs = await sandbox.computer_use.get_process_logs("novnc")
print("NoVNC logs:", logs)
AsyncComputerUse.get_process_errors
@intercept_errors(message_prefix="Failed to get process errors: ")
async def get_process_errors(process_name: str) -> ProcessErrorsResponse
特定のVNCプロセスのエラーログを取得します。
引数:
process_namestr - エラーログを取得するプロセス名。
戻り値:
ProcessErrorsResponse- プロセスのエラーログ。
例:
errors = await sandbox.computer_use.get_process_errors("x11vnc")
print("X11VNC errors:", errors)
AsyncMouse
class AsyncMouse()
コンピューター操作機能のためのマウス操作。
AsyncMouse.get_position
@intercept_errors(message_prefix="Failed to get mouse position: ")
async def get_position() -> MousePosition
現在のマウスカーソル位置を取得します。
Returns:
MousePosition- x座標とy座標を含む現在のマウス位置。
Example:
position = await sandbox.computer_use.mouse.get_position()
print(f"Mouse is at: {position.x}, {position.y}")
AsyncMouse.move
@intercept_errors(message_prefix="Failed to move mouse: ")
async def move(x: int, y: int) -> MouseMoveResponse
マウスカーソルを指定した座標に移動します。
Arguments:
xint - 移動先のx座標。yint - 移動先のy座標。
Returns:
MouseMoveResponse- 移動操作の結果。
Example:
result = await sandbox.computer_use.mouse.move(100, 200)
print(f"Mouse moved to: {result.x}, {result.y}")
AsyncMouse.click
@intercept_errors(message_prefix="Failed to click mouse: ")
async def click(x: int,
y: int,
button: str = "left",
double: bool = False) -> MouseClickResponse
指定した座標でマウスをクリックします。
Arguments:
xint - クリックするx座標。yint - クリックするy座標。buttonstr - クリックするマウスボタン(‘left’、‘right’、‘middle’)。doublebool - ダブルクリックを行うかどうか。
Returns:
MouseClickResponse- クリック操作の結果。
Example:
# Single left click
result = await sandbox.computer_use.mouse.click(100, 200)
# Double click
double_click = await sandbox.computer_use.mouse.click(100, 200, "left", True)
# Right click
right_click = await sandbox.computer_use.mouse.click(100, 200, "right")
AsyncMouse.drag
@intercept_errors(message_prefix="Failed to drag mouse: ")
async def drag(start_x: int,
start_y: int,
end_x: int,
end_y: int,
button: str = "left") -> MouseDragResponse
開始座標から終了座標までマウスをドラッグします。
Arguments:
start_xint - 開始x座標。start_yint - 開始y座標。end_xint - 終了x座標。end_yint - 終了y座標。buttonstr - ドラッグに使用するマウスボタン。
Returns:
MouseDragResponse- ドラッグ操作の結果。
Example:
result = await sandbox.computer_use.mouse.drag(50, 50, 150, 150)
print(f"Dragged from {result.from_x},{result.from_y} to {result.to_x},{result.to_y}")
AsyncMouse.scroll
@intercept_errors(message_prefix="Failed to scroll mouse: ")
async def scroll(x: int, y: int, direction: str, amount: int = 1) -> bool
指定した座標でマウスホイールをスクロールします。
Arguments:
xint - スクロールするx座標。yint - スクロールするy座標。directionstr - スクロール方向(‘up’ または ‘down’)。amountint - スクロール量。
Returns:
bool- スクロール操作が成功したかどうか。
Example:
# Scroll up
scroll_up = await sandbox.computer_use.mouse.scroll(100, 200, "up", 3)
# Scroll down
scroll_down = await sandbox.computer_use.mouse.scroll(100, 200, "down", 5)
AsyncKeyboard
class AsyncKeyboard()
コンピューター操作(Computer Use)機能におけるキーボード操作。
AsyncKeyboard.type
@intercept_errors(message_prefix="Failed to type text: ")
async def type(text: str, delay: Optional[int] = None) -> None
指定したテキストを入力します。
Arguments:
textstr - 入力するテキスト。delayint - 文字ごとの遅延(ミリ秒)。
Raises:
DaytonaError- 入力処理に失敗した場合。
Example:
try:
await sandbox.computer_use.keyboard.type("Hello, World!")
print(f"Operation success")
except Exception as e:
print(f"Operation failed: {e}")
# 文字ごとに遅延を入れる場合
try:
await sandbox.computer_use.keyboard.type("Slow typing", 100)
print(f"Operation success")
except Exception as e:
print(f"Operation failed: {e}")
AsyncKeyboard.press
@intercept_errors(message_prefix="Failed to press key: ")
async def press(key: str, modifiers: Optional[List[str]] = None) -> None
必要に応じてモディファイアキーと組み合わせてキーを押します。
Arguments:
keystr - 押下するキー(例: ‘Enter’, ‘Escape’, ‘Tab’, ‘a’, ‘A’)。modifiersList[str] - モディファイアキー(‘ctrl’, ‘alt’, ‘meta’, ‘shift’)。
Raises:
DaytonaError- キー押下処理に失敗した場合。
Example:
# Enter を押す
try:
await sandbox.computer_use.keyboard.press("Return")
print(f"Operation success")
except Exception as e:
print(f"Operation failed: {e}")
# Ctrl+C を押す
try:
await sandbox.computer_use.keyboard.press("c", ["ctrl"])
print(f"Operation success")
# Ctrl+Shift+T を押す
try:
await sandbox.computer_use.keyboard.press("t", ["ctrl", "shift"])
print(f"Operation success")
except Exception as e:
print(f"Operation failed: {e}")
AsyncKeyboard.hotkey
@intercept_errors(message_prefix="Failed to press hotkey: ")
async def hotkey(keys: str) -> None
ホットキーの組み合わせを押します。
Arguments:
keysstr - ホットキーの組み合わせ(例: ‘ctrl+c’, ‘alt+tab’, ‘cmd+shift+t’)。
Raises:
DaytonaError- ホットキー処理に失敗した場合。
Example:
# コピー
try:
await sandbox.computer_use.keyboard.hotkey("ctrl+c")
print(f"Operation success")
except Exception as e:
print(f"Operation failed: {e}")
# ペースト
try:
await sandbox.computer_use.keyboard.hotkey("ctrl+v")
print(f"Operation success")
except Exception as e:
print(f"Operation failed: {e}")
# Alt+Tab
try:
await sandbox.computer_use.keyboard.hotkey("alt+tab")
print(f"Operation success")
except Exception as e:
print(f"Operation failed: {e}")
AsyncScreenshot
class AsyncScreenshot()
コンピューター操作(Computer Use)機能向けのスクリーンショット処理。
AsyncScreenshot.take_full_screen
@intercept_errors(message_prefix="Failed to take screenshot: ")
async def take_full_screen(show_cursor: bool = False) -> ScreenshotResponse
画面全体のスクリーンショットを取得します。
引数:
show_cursorbool - スクリーンショットにカーソルを表示するかどうか。
戻り値:
ScreenshotResponse- 画像をbase64エンコードしたスクリーンショットデータ。
例:
screenshot = await sandbox.computer_use.screenshot.take_full_screen()
print(f"Screenshot size: {screenshot.width}x{screenshot.height}")
# With cursor visible
with_cursor = await sandbox.computer_use.screenshot.take_full_screen(True)
AsyncScreenshot.take_region
@intercept_errors(message_prefix="Failed to take region screenshot: ")
async def take_region(region: ScreenshotRegion,
show_cursor: bool = False) -> RegionScreenshotResponse
指定した領域のスクリーンショットを取得します。
引数:
regionScreenshotRegion - 取得対象の領域。show_cursorbool - スクリーンショットにカーソルを表示するかどうか。
戻り値:
RegionScreenshotResponse- 画像をbase64エンコードしたスクリーンショットデータ。
例:
region = ScreenshotRegion(x=100, y=100, width=300, height=200)
screenshot = await sandbox.computer_use.screenshot.take_region(region)
print(f"Captured region: {screenshot.region.width}x{screenshot.region.height}")
AsyncScreenshot.take_compressed
@intercept_errors(message_prefix="Failed to take compressed screenshot: ")
async def take_compressed(
options: Optional[ScreenshotOptions] = None
) -> CompressedScreenshotResponse
画面全体の圧縮スクリーンショットを取得します。
引数:
optionsScreenshotOptions - 圧縮および表示のオプション。
戻り値:
CompressedScreenshotResponse- 圧縮済みスクリーンショットデータ。
例:
# Default compression
screenshot = await sandbox.computer_use.screenshot.take_compressed()
# High quality JPEG
jpeg = await sandbox.computer_use.screenshot.take_compressed(
ScreenshotOptions(format="jpeg", quality=95, show_cursor=True)
)
# Scaled down PNG
scaled = await sandbox.computer_use.screenshot.take_compressed(
ScreenshotOptions(format="png", scale=0.5)
)
AsyncScreenshot.take_compressed_region
@intercept_errors(
message_prefix="Failed to take compressed region screenshot: ")
async def take_compressed_region(
region: ScreenshotRegion,
options: Optional[ScreenshotOptions] = None
) -> CompressedScreenshotResponse
指定した領域の圧縮スクリーンショットを取得します。
引数:
regionScreenshotRegion - 取得対象の領域。optionsScreenshotOptions - 圧縮および表示のオプション。
戻り値:
CompressedScreenshotResponse- 圧縮済みスクリーンショットデータ。
例:
region = ScreenshotRegion(x=0, y=0, width=800, height=600)
screenshot = await sandbox.computer_use.screenshot.take_compressed_region(
region,
ScreenshotOptions(format="webp", quality=80, show_cursor=True)
)
print(f"Compressed size: {screenshot.size_bytes} bytes")
AsyncDisplay
class AsyncDisplay()
コンピューター操作機能向けのディスプレイ操作。
AsyncDisplay.get_info
@intercept_errors(message_prefix="Failed to get display info: ")
async def get_info() -> DisplayInfoResponse
ディスプレイ情報を取得します。
Returns:
DisplayInfoResponse- プライマリディスプレイおよび利用可能なすべてのディスプレイを含む情報。
Example:
info = await sandbox.computer_use.display.get_info()
print(f"Primary display: {info.primary_display.width}x{info.primary_display.height}")
print(f"Total displays: {info.total_displays}")
for i, display in enumerate(info.displays):
print(f"Display {i}: {display.width}x{display.height} at {display.x},{display.y}")
AsyncDisplay.get_windows
@intercept_errors(message_prefix="Failed to get windows: ")
async def get_windows() -> WindowsResponse
開いているウィンドウの一覧を取得します。
Returns:
WindowsResponse- IDとタイトルを含む開いているウィンドウの一覧。
Example:
windows = await sandbox.computer_use.display.get_windows()
print(f"Found {windows.count} open windows:")
for window in windows.windows:
print(f"- {window.title} (ID: {window.id})")
ScreenshotRegion
class ScreenshotRegion()
スクリーンショット操作のための領域座標。
属性:
xint - 領域のX座標。yint - 領域のY座標。widthint - 領域の幅。heightint - 領域の高さ。
ScreenshotOptions
class ScreenshotOptions()
スクリーンショットの圧縮や表示に関するオプション。
属性:
show_cursorbool - スクリーンショットにカーソルを表示するかどうか。fmtstr - 画像形式(例: ‘png’、‘jpeg’、‘webp’)。qualityint - 圧縮品質(0〜100)。scalefloat - スクリーンショットの拡大率。