|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +## Sandbox |
| 7 | + |
| 8 | +```python |
| 9 | +class Sandbox(SandboxBase) |
| 10 | +``` |
| 11 | + |
| 12 | + |
| 13 | +### \_\_init\_\_ |
| 14 | + |
| 15 | +```python |
| 16 | +def __init__(resolution: Optional[Tuple[int, int]] = None, |
| 17 | + dpi: Optional[int] = None, |
| 18 | + display: Optional[str] = None, |
| 19 | + template: Optional[str] = None, |
| 20 | + timeout: Optional[int] = None, |
| 21 | + metadata: Optional[Dict[str, str]] = None, |
| 22 | + envs: Optional[Dict[str, str]] = None, |
| 23 | + api_key: Optional[str] = None, |
| 24 | + domain: Optional[str] = None, |
| 25 | + debug: Optional[bool] = None, |
| 26 | + sandbox_id: Optional[str] = None, |
| 27 | + request_timeout: Optional[float] = None, |
| 28 | + proxy: Optional[ProxyTypes] = None) |
| 29 | +``` |
| 30 | + |
| 31 | +Create a new desktop sandbox. |
| 32 | + |
| 33 | +By default, the sandbox is created from the `desktop` template. |
| 34 | + |
| 35 | +**Arguments**: |
| 36 | + |
| 37 | +- `resolution`: Startup the desktop with custom screen resolution. Defaults to (1024, 768) |
| 38 | +- `dpi`: Startup the desktop with custom DPI. Defaults to 96 |
| 39 | +- `display`: Startup the desktop with custom display. Defaults to ":0" |
| 40 | +- `template`: Sandbox template name or ID |
| 41 | +- `timeout`: Timeout for the sandbox in **seconds**, default to 300 seconds. Maximum time a sandbox can be kept alive is 24 hours (86_400 seconds) for Pro users and 1 hour (3_600 seconds) for Hobby users |
| 42 | +- `metadata`: Custom metadata for the sandbox |
| 43 | +- `envs`: Custom environment variables for the sandbox |
| 44 | +- `api_key`: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable |
| 45 | +- `domain`: E2B domain to use for authentication, defaults to `E2B_DOMAIN` environment variable |
| 46 | +- `debug`: If True, the sandbox will be created in debug mode, defaults to `E2B_DEBUG` environment variable |
| 47 | +- `sandbox_id`: Sandbox ID to connect to, defaults to `E2B_SANDBOX_ID` environment variable |
| 48 | +- `request_timeout`: Timeout for the request in **seconds** |
| 49 | +- `proxy`: Proxy to use for the request and for the requests made to the returned sandbox |
| 50 | + |
| 51 | +**Returns**: |
| 52 | + |
| 53 | +sandbox instance for the new sandbox |
| 54 | + |
| 55 | + |
| 56 | +### screenshot |
| 57 | + |
| 58 | +```python |
| 59 | +@overload |
| 60 | +def screenshot(format: Literal["stream"]) -> Iterator[bytes] |
| 61 | +``` |
| 62 | + |
| 63 | +Take a screenshot and return it as a stream of bytes. |
| 64 | + |
| 65 | + |
| 66 | +### screenshot |
| 67 | + |
| 68 | +```python |
| 69 | +@overload |
| 70 | +def screenshot(format: Literal["bytes"]) -> bytearray |
| 71 | +``` |
| 72 | + |
| 73 | +Take a screenshot and return it as a bytearray. |
| 74 | + |
| 75 | + |
| 76 | +### screenshot |
| 77 | + |
| 78 | +```python |
| 79 | +def screenshot(format: Literal["bytes", "stream"] = "bytes") |
| 80 | +``` |
| 81 | + |
| 82 | +Take a screenshot and return it in the specified format. |
| 83 | + |
| 84 | +**Arguments**: |
| 85 | + |
| 86 | +- `format`: The format of the screenshot. Can be 'bytes', 'blob', or 'stream'. |
| 87 | + |
| 88 | +**Returns**: |
| 89 | + |
| 90 | +The screenshot in the specified format. |
| 91 | + |
| 92 | + |
| 93 | +### left\_click |
| 94 | + |
| 95 | +```python |
| 96 | +def left_click(x: Optional[int] = None, y: Optional[int] = None) |
| 97 | +``` |
| 98 | + |
| 99 | +Left click on the mouse position. |
| 100 | + |
| 101 | + |
| 102 | +### double\_click |
| 103 | + |
| 104 | +```python |
| 105 | +def double_click(x: Optional[int] = None, y: Optional[int] = None) |
| 106 | +``` |
| 107 | + |
| 108 | +Double left click on the mouse position. |
| 109 | + |
| 110 | + |
| 111 | +### middle\_click |
| 112 | + |
| 113 | +```python |
| 114 | +def middle_click(x: Optional[int] = None, y: Optional[int] = None) |
| 115 | +``` |
| 116 | + |
| 117 | +Middle click on the mouse position. |
| 118 | + |
| 119 | + |
| 120 | +### scroll |
| 121 | + |
| 122 | +```python |
| 123 | +def scroll(direction: Literal["up", "down"] = "down", amount: int = 1) |
| 124 | +``` |
| 125 | + |
| 126 | +Scroll the mouse wheel by the given amount. |
| 127 | + |
| 128 | +**Arguments**: |
| 129 | + |
| 130 | +- `direction`: The direction to scroll. Can be "up" or "down". |
| 131 | +- `amount`: The amount to scroll. |
| 132 | + |
| 133 | + |
| 134 | +### move\_mouse |
| 135 | + |
| 136 | +```python |
| 137 | +def move_mouse(x: int, y: int) |
| 138 | +``` |
| 139 | + |
| 140 | +Move the mouse to the given coordinates. |
| 141 | + |
| 142 | +**Arguments**: |
| 143 | + |
| 144 | +- `x`: The x coordinate. |
| 145 | +- `y`: The y coordinate. |
| 146 | + |
| 147 | + |
| 148 | +### mouse\_press |
| 149 | + |
| 150 | +```python |
| 151 | +def mouse_press(button: Literal["left", "right", "middle"] = "left") |
| 152 | +``` |
| 153 | + |
| 154 | +Press the mouse button. |
| 155 | + |
| 156 | + |
| 157 | +### mouse\_release |
| 158 | + |
| 159 | +```python |
| 160 | +def mouse_release(button: Literal["left", "right", "middle"] = "left") |
| 161 | +``` |
| 162 | + |
| 163 | +Release the mouse button. |
| 164 | + |
| 165 | + |
| 166 | +### get\_cursor\_position |
| 167 | + |
| 168 | +```python |
| 169 | +def get_cursor_position() -> tuple[int, int] |
| 170 | +``` |
| 171 | + |
| 172 | +Get the current cursor position. |
| 173 | + |
| 174 | +**Raises**: |
| 175 | + |
| 176 | +- `RuntimeError`: If the cursor position cannot be determined |
| 177 | + |
| 178 | +**Returns**: |
| 179 | + |
| 180 | +A tuple with the x and y coordinates |
| 181 | + |
| 182 | + |
| 183 | +### get\_screen\_size |
| 184 | + |
| 185 | +```python |
| 186 | +def get_screen_size() -> tuple[int, int] |
| 187 | +``` |
| 188 | + |
| 189 | +Get the current screen size. |
| 190 | + |
| 191 | +**Raises**: |
| 192 | + |
| 193 | +- `RuntimeError`: If the screen size cannot be determined |
| 194 | + |
| 195 | +**Returns**: |
| 196 | + |
| 197 | +A tuple with the width and height |
| 198 | + |
| 199 | + |
| 200 | +### write |
| 201 | + |
| 202 | +```python |
| 203 | +def write(text: str, *, chunk_size: int = 25, delay_in_ms: int = 75) -> None |
| 204 | +``` |
| 205 | + |
| 206 | +Write the given text at the current cursor position. |
| 207 | + |
| 208 | +**Arguments**: |
| 209 | + |
| 210 | +- `text`: The text to write. |
| 211 | +- `chunk_size`: The size of each chunk of text to write. |
| 212 | +- `delay_in_ms`: The delay between each chunk of text. |
| 213 | + |
| 214 | + |
| 215 | +### press |
| 216 | + |
| 217 | +```python |
| 218 | +def press(key: Union[str, list[str]]) |
| 219 | +``` |
| 220 | + |
| 221 | +Press a key. |
| 222 | + |
| 223 | +**Arguments**: |
| 224 | + |
| 225 | +- `key`: The key to press (e.g. "enter", "space", "backspace", etc.). |
| 226 | + |
| 227 | + |
| 228 | +### drag |
| 229 | + |
| 230 | +```python |
| 231 | +def drag(fr: tuple[int, int], to: tuple[int, int]) |
| 232 | +``` |
| 233 | + |
| 234 | +Drag the mouse from the given position to the given position. |
| 235 | + |
| 236 | +**Arguments**: |
| 237 | + |
| 238 | +- `from`: The starting position. |
| 239 | +- `to`: The ending position. |
| 240 | + |
| 241 | + |
| 242 | +### wait |
| 243 | + |
| 244 | +```python |
| 245 | +def wait(ms: int) |
| 246 | +``` |
| 247 | + |
| 248 | +Wait for the given amount of time. |
| 249 | + |
| 250 | +**Arguments**: |
| 251 | + |
| 252 | +- `ms`: The amount of time to wait in milliseconds. |
| 253 | + |
| 254 | + |
| 255 | +### open |
| 256 | + |
| 257 | +```python |
| 258 | +def open(file_or_url: str) |
| 259 | +``` |
| 260 | + |
| 261 | +Open a file or a URL in the default application. |
| 262 | + |
| 263 | +**Arguments**: |
| 264 | + |
| 265 | +- `file_or_url`: The file or URL to open. |
| 266 | + |
| 267 | + |
| 268 | +### get\_current\_window\_id |
| 269 | + |
| 270 | +```python |
| 271 | +def get_current_window_id() -> str |
| 272 | +``` |
| 273 | + |
| 274 | +Get the current window ID. |
| 275 | + |
| 276 | + |
| 277 | +### get\_application\_windows |
| 278 | + |
| 279 | +```python |
| 280 | +def get_application_windows(application: str) -> list[str] |
| 281 | +``` |
| 282 | + |
| 283 | +Get the window IDs of all windows for the given application. |
| 284 | + |
| 285 | + |
| 286 | +### get\_window\_title |
| 287 | + |
| 288 | +```python |
| 289 | +def get_window_title(window_id: str) -> str |
| 290 | +``` |
| 291 | + |
| 292 | +Get the title of the window with the given ID. |
| 293 | + |
| 294 | + |
| 295 | +### launch |
| 296 | + |
| 297 | +```python |
| 298 | +def launch(application: str, uri: Optional[str] = None) |
| 299 | +``` |
| 300 | + |
| 301 | +Launch an application. |
| 302 | + |
0 commit comments