> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hopx.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Window Management

> Manage windows on the sandbox desktop including resizing, moving, and focusing windows in HopX sandboxes. Control window positions, sizes, focus, and visibility for desktop automation workflows. Learn how to manage windows using Python and JavaScript SDKs or REST API. Includes examples for window automation and GUI testing.

Manage windows on the desktop: list, focus, resize, minimize, and close windows.

## Overview

Window management enables:

* Listing all windows
* Focusing (activating) windows
* Resizing windows
* Minimizing windows
* Closing windows

<Note>
  Desktop automation requires a template with desktop support. Ensure your sandbox has desktop capabilities enabled.
</Note>

## Listing Windows

Get list of all windows:

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from hopx_ai import Sandbox

    sandbox = Sandbox.create(template="desktop")

    # Get all windows
    windows = sandbox.desktop.get_windows()

    for window in windows:
        print(f"Window: {window.title}")
        print(f"  ID: {window.id}")
        print(f"  Position: ({window.x}, {window.y})")
        print(f"  Size: {window.width}x{window.height}")
        print(f"  PID: {window.pid}")
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    import { Sandbox } from '@hopx-ai/sdk';

    const sandbox = await Sandbox.create({ template: 'desktop' });

    // Get all windows
    const windows = await sandbox.desktop.listWindows();

    windows.forEach(window => {
      console.log(`Window: ${window.title}`);
      console.log(`  ID: ${window.id}`);
      console.log(`  Position: (${window.x}, ${window.y})`);
      console.log(`  Size: ${window.width}x${window.height}`);
      console.log(`  PID: ${window.pid}`);
    });
    ```
  </Tab>
</Tabs>

## Focusing Windows

Focus (activate) a window:

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    # Get windows
    windows = sandbox.desktop.get_windows()

    # Focus first window
    if windows:
        sandbox.desktop.focus_window(windows[0].id)

    # Find and focus window by title
    for window in windows:
        if "Firefox" in window.title:
            sandbox.desktop.focus_window(window.id)
            break
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    // Get windows
    const windows = await sandbox.desktop.listWindows();

    // Focus first window
    if (windows.length > 0) {
      await sandbox.desktop.focusWindow(windows[0].id);
    }

    // Find and focus window by title
    for (const window of windows) {
      if (window.title.includes('Firefox')) {
        await sandbox.desktop.focusWindow(window.id);
        break;
      }
    }
    ```
  </Tab>
</Tabs>

## Resizing Windows

Resize a window:

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    # Get windows
    windows = sandbox.desktop.get_windows()

    # Resize first window to 800x600
    if windows:
        sandbox.desktop.resize_window(windows[0].id, 800, 600)

    # Resize window by title
    for window in windows:
        if "My App" in window.title:
            sandbox.desktop.resize_window(window.id, 1024, 768)
            break
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    // Get windows
    const windows = await sandbox.desktop.listWindows();

    // Resize first window to 800x600
    if (windows.length > 0) {
      await sandbox.desktop.resizeWindow(windows[0].id, 800, 600);
    }

    // Resize window by title
    for (const window of windows) {
      if (window.title.includes('My App')) {
        await sandbox.desktop.resizeWindow(window.id, 1024, 768);
        break;
      }
    }
    ```
  </Tab>
</Tabs>

## Minimizing Windows

Minimize a window:

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    # Minimize first window
    windows = sandbox.desktop.get_windows()
    if windows:
        sandbox.desktop.minimize_window(windows[0].id)
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    // Minimize first window
    const windows = await sandbox.desktop.listWindows();
    if (windows.length > 0) {
      await sandbox.desktop.minimizeWindow(windows[0].id);
    }
    ```
  </Tab>
</Tabs>

## Closing Windows

Close a window:

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    # Close window by title
    windows = sandbox.desktop.get_windows()
    for window in windows:
        if "Firefox" in window.title:
            sandbox.desktop.close_window(window.id)
            break
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    // Close window by title
    const windows = await sandbox.desktop.listWindows();
    for (const window of windows) {
      if (window.title.includes('Firefox')) {
        await sandbox.desktop.closeWindow(window.id);
        break;
      }
    }
    ```
  </Tab>
</Tabs>

## Window Information

Window objects contain:

* **id**: Unique window identifier
* **title**: Window title/name
* **x, y**: Window position (top-left corner)
* **width, height**: Window size
* **desktop**: Desktop number (for multi-desktop)
* **pid**: Process ID of the window

## Complete Example

Complete window management workflow:

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from hopx_ai import Sandbox

    sandbox = Sandbox.create(template="desktop")

    try:
        # List all windows
        windows = sandbox.desktop.get_windows()
        print(f"Found {len(windows)} windows")
        
        # Find specific window
        target_window = None
        for window in windows:
            if "My Application" in window.title:
                target_window = window
                break
        
        if target_window:
            # Focus window
            sandbox.desktop.focus_window(target_window.id)
            print(f"Focused: {target_window.title}")
            
            # Resize window
            sandbox.desktop.resize_window(target_window.id, 1024, 768)
            print("Resized to 1024x768")
            
            # Minimize
            sandbox.desktop.minimize_window(target_window.id)
            print("Minimized")
            
            # Close
            sandbox.desktop.close_window(target_window.id)
            print("Closed")
        
    finally:
        sandbox.kill()
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    import { Sandbox } from '@hopx-ai/sdk';

    const sandbox = await Sandbox.create({ template: 'desktop' });

    try {
      // List all windows
      const windows = await sandbox.desktop.listWindows();
      console.log(`Found ${windows.length} windows`);
      
      // Find specific window
      const targetWindow = windows.find(w => w.title.includes('My Application'));
      
      if (targetWindow) {
        // Focus window
        await sandbox.desktop.focusWindow(targetWindow.id);
        console.log(`Focused: ${targetWindow.title}`);
        
        // Resize window
        await sandbox.desktop.resizeWindow(targetWindow.id, 1024, 768);
        console.log('Resized to 1024x768');
        
        // Minimize
        await sandbox.desktop.minimizeWindow(targetWindow.id);
        console.log('Minimized');
        
        // Close
        await sandbox.desktop.closeWindow(targetWindow.id);
        console.log('Closed');
      }
      
    } finally {
      await sandbox.kill();
    }
    ```
  </Tab>
</Tabs>

## Related

* [Display Management](/core-concepts/desktop/display-management) - Configure display settings
* [VNC Server](/core-concepts/desktop/vnc-server) - Remote desktop access
* **SDK**: [sandbox.desktop.get\_windows()](/sdk/python/desktop#get_windows) - Python SDK method

## Next Steps

* Learn about [Display Management](/core-concepts/desktop/display-management) to configure display

* Explore [VNC Server](/core-concepts/desktop/vnc-server) for remote desktop access

* Review [Screenshots](/core-concepts/desktop/screenshots) for visual verification

* [Display Management](/core-concepts/desktop/display-management) - Configure display settings

* [Screenshots](/core-concepts/desktop/screenshots) - Capture window screenshots

* **[CLI System Commands](/cli/commands/system)** - System operations from CLI
