> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.scrapybara.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.scrapybara.com/_mcp/server.

# Ubuntu

## UbuntuInstance

The `UbuntuInstance` is a Ubuntu 22.04 desktop that supports interactive streaming, computer actions, bash commands, filesystem management, built-in Jupyter notebooks, and Chromium browser support. We recommend using this instance type for most tasks.

* Fast start up time
* 1x compute cost

## Start an Ubuntu instance

#### Python

`python instance = client.start_ubuntu() `

#### TypeScript

`typescript const instance = await client.startUbuntu(); `

## Available actions

### screenshot

Take a base64 encoded image of the current desktop

#### Python

`python base_64_image = instance.screenshot().base_64_image `

#### TypeScript

`typescript const base64Image = await instance.screenshot(); `

### get\_stream\_url

Get the interactive stream URL

#### Python

`python stream_url = instance.get_stream_url().stream_url `

#### TypeScript

`typescript const streamUrl = await instance.getStreamUrl(); `

### computer

Perform computer actions with the mouse and keyboard

#### `move_mouse`

Move mouse cursor to specific coordinates

**`coordinates`** `array` — required

\[x, y] coordinates to move to

---

**`hold_keys`** `array`

List of modifier keys to hold during the action

---

**`screenshot`** `boolean` — default: true

Whether to take a screenshot after the action

---

#### Python

```python Move mouse
instance.computer(action="move_mouse", coordinates=[100, 200])
```

```python Move mouse while holding shift
instance.computer(action="move_mouse", coordinates=[100, 200], hold_keys=["shift"])
```

```python Move mouse without taking a screenshot
instance.computer(action="move_mouse", coordinates=[100, 200], screenshot=False)
```

#### TypeScript

```typescript Move mouse
await instance.computer({action: "move_mouse", coordinates: [100, 200]});
```

```typescript Move mouse while holding shift
await instance.computer({action: "move_mouse", coordinates: [100, 200], holdKeys: ["shift"]});
```

```typescript Move mouse without taking a screenshot
await instance.computer({action: "move_mouse", coordinates: [100, 200], screenshot: false});
```

#### `click_mouse`

Perform a mouse click at current position or specified coordinates

**`button`** `string` — required

Mouse button to click ("left", "right", "middle", "back", "forward")

---

**`click_type`** `string` — default: click

Type of click action ("down", "up", "click")

---

**`coordinates`** `array`

\[x, y] coordinates to click at

---

**`num_clicks`** `number` — default: 1

Number of clicks

---

**`hold_keys`** `array`

List of modifier keys to hold during the action

---

**`screenshot`** `boolean` — default: true

Whether to take a screenshot after the action

---

#### Python

```python Left click at current position
instance.computer(action="click_mouse", button="left")
```

```python Right click at coordinates
instance.computer(action="click_mouse", button="right", coordinates=[300, 400])
```

```python Mouse down
instance.computer(action="click_mouse", button="left", click_type="down")
```

```python Double click at coordinates
instance.computer(action="click_mouse", button="left", num_clicks=2, coordinates=[500, 300])
```

#### TypeScript

```typescript Left click at current position
await instance.computer({action: "click_mouse", button: "left"});
```

```typescript Right click at coordinates
await instance.computer({action: "click_mouse", button: "right", coordinates: [300, 400]});
```

```typescript Mouse down
await instance.computer({action: "click_mouse", button: "left", clickType: "down"});
```

```typescript Double click at coordinates
await instance.computer({action: "click_mouse", button: "left", numClicks: 2, coordinates: [500, 300]});
```

#### `drag_mouse`

Click and drag from current position to specified coordinates

**`path`** `array` — required

List of \[x, y] coordinate pairs defining the drag path

---

**`hold_keys`** `array`

List of modifier keys to hold during the action

---

**`screenshot`** `boolean` — default: true

Whether to take a screenshot after the action

---

#### Python

```python Drag to coordinates
instance.computer(action="drag_mouse", path=[[100, 200], [300, 400]])
```

#### TypeScript

```typescript Drag to coordinates
await instance.computer({action: "drag_mouse", path: [[100, 200], [300, 400]]});
```

#### `scroll`

Scroll horizontally and/or vertically

**`coordinates`** `array`

\[x, y] coordinates to scroll at

---

**`delta_x`** `number` — default: 0

Horizontal scroll amount

---

**`delta_y`** `number` — default: 0

Vertical scroll amount

---

**`hold_keys`** `array`

List of modifier keys to hold during the action

---

**`screenshot`** `boolean` — default: true

Whether to take a screenshot after the action

---

#### Python

```python Scroll down
instance.computer(action="scroll", coordinates=[100, 100], delta_x=0, delta_y=200)
```

```python Scroll right
instance.computer(action="scroll", coordinates=[100, 100], delta_x=200, delta_y=0)
```

#### TypeScript

```typescript Scroll down
await instance.computer({action: "scroll", coordinates: [100, 100], deltaX: 0, deltaY: 200});
```

```typescript Scroll right
await instance.computer({action: "scroll", coordinates: [100, 100], deltaX: 100, deltaY: 0});
```

#### `press_key`

Press a key or combination of keys. Scrapybara supports keys defined by [X keysyms](https://github.com/D-Programming-Deimos/libX11/blob/master/c/X11/keysymdef.h). Common aliases are also supported:

* `alt` → `Alt_L`
* `ctrl`, `control` → `Control_L`
* `meta` → `Meta_L`
* `super` → `Super_L`
* `shift` → `Shift_L`

**`keys`** `array` — required

List of keys to press

---

**`duration`** `number`

Time to hold keys in seconds

---

**`screenshot`** `boolean` — default: true

Whether to take a screenshot after the action

---

#### Python

```python Press ctrl+c
instance.computer(action="press_key", keys=["ctrl", "c"])
```

```python Hold shift for 2 seconds
instance.computer(action="press_key", keys=["shift"], duration=2)
```

```python Press enter/return
instance.computer(action="press_key", keys=["Return"])
```

#### TypeScript

```typescript Press ctrl+c
await instance.computer({action: "press_key", keys: ["ctrl", "c"]});
```

```typescript Hold shift for 2 seconds
await instance.computer({action: "press_key", keys: ["shift"], duration: 2});
```

```typescript Press enter/return
await instance.computer({action: "press_key", keys: ["Return"]});
```

#### `type_text`

Type text into the active window

**`text`** `string` — required

Text to type

---

**`hold_keys`** `array`

List of modifier keys to hold while typing

---

**`screenshot`** `boolean` — default: true

Whether to take a screenshot after the action

---

#### Python

```python Type text
instance.computer(action="type_text", text="Hello world")
```

```python Type text without taking a screenshot
instance.computer(action="type_text", text="Hello world", screenshot=False)
```

#### TypeScript

```typescript Type text
await instance.computer({action: "type_text", text: "Hello world"});
```

```typescript Type text without taking a screenshot
await instance.computer({action: "type_text", text: "Hello world", screenshot: false});
```

#### `wait`

Wait for a specified duration

**`duration`** `number` — required

Time to wait in seconds

---

**`screenshot`** `boolean` — default: true

Whether to take a screenshot after the action

---

#### Python

```python Wait for 3 seconds
instance.computer(action="wait", duration=3)
```

#### TypeScript

```typescript Wait for 3 seconds
await instance.computer({action: "wait", duration: 3});
```

#### `take_screenshot`

Take a screenshot of the desktop

#### Python

```python
screenshot = instance.computer(action="take_screenshot").base_64_image
```

#### TypeScript

```typescript
const screenshot = await instance.computer({action: "take_screenshot"}).base64Image;
```

#### `get_cursor_position`

Get current mouse cursor coordinates

#### Python

```python
cursor_position = instance.computer(action="get_cursor_position").output
```

#### TypeScript

```typescript
const cursorPosition = await instance.computer({action: "get_cursor_position"}).output;
```

### bash

Run a bash command

> **Note:** Bash commands time out after 10 seconds by default, but you can customize this with the `timeout` parameter. When a command times out, it will continue running in the session. To run other commands while waiting for a long-running command to complete, start them in a different session. Use `check_session` to check back on a session's status. Once a command finishes execution, the session becomes available again for new commands.

#### Python

```python Run a bash command
output = instance.bash(command="ls -la")
```

```python Run a command in a specific session
output = instance.bash(command="ls -la", session=1)
```

```python Run a command with custom timeout
output = instance.bash(command="sleep 30", timeout=60)
```

```python Restart a session
instance.bash(restart=True, session=1)
```

```python List available bash sessions
sessions = instance.bash(list_sessions=True)
```

```python Check the status of a session
session_exists = instance.bash(check_session=1)
```

#### TypeScript

```typescript Run a bash command
const output = await instance.bash({command: "ls -la"});
```

```typescript Run a command in a specific session
const output = await instance.bash({command: "ls -la", session: 1});
```

```typescript Run a command with custom timeout
const output = await instance.bash({command: "sleep 30", timeout: 60});
```

```typescript Restart a session
await instance.bash({restart: true, session: 1});
```

```typescript List available bash sessions
const sessions = await instance.bash({listSessions: true});
```

```typescript Check the status of a session
const sessionExists = await instance.bash({checkSession: 1});
```

### edit

> **Deprecated:** Please use the `file` tool instead which provides more comprehensive file management capabilities.

Edit a file on the instance

#### Python

```python Create a new file
instance.edit(command="create", path="hello.txt", file_text="Hello world")
```

```python Replace text in a file
instance.edit(command="str_replace", path="hello.txt", old_str="Hello", new_str="Hi")
```

```python Insert text at a specific line
instance.edit(command="insert", path="hello.txt", insert_line=2, file_text="New line")
```

#### TypeScript

```typescript Create a new file
await instance.edit({command: "create", path: "hello.txt", fileText: "Hello world"});
```

```typescript Replace text in a file
await instance.edit({command: "str_replace", path: "hello.txt", oldStr: "Hello", newStr: "Hi"});
```

```typescript Insert text at a specific line
await instance.edit({command: "insert", path: "hello.txt", insertLine: 2, fileText: "New line"});
```

### file

Manage files and directories on the instance

#### `read`

Read the content of a file in text or binary mode

**`path`** `string` — required

Path to the file to read

---

**`mode`** `string` — default: text

Read mode: "text" or "binary"

---

**`encoding`** `string` — default: utf-8

Text encoding when mode is "text"

---

#### Python

```python Read text file
content = instance.file(command="read", path="my_file.txt")
```

```python Read binary file
binary_content = instance.file(command="read", path="image.png", mode="binary")
```

#### TypeScript

```typescript Read text file
const content = await instance.file({command: "read", path: "my_file.txt"});
```

```typescript Read binary file
const binaryContent = await instance.file({command: "read", path: "image.png", mode: "binary"});
```

#### `write`

Write content to a file, overwriting if it exists

**`path`** `string` — required

Path to the file to write

---

**`content`** `string` — required

Content to write to the file

---

**`mode`** `string` — default: text

Write mode: "text" or "binary" (base64 encoded for binary)

---

**`encoding`** `string` — default: utf-8

Text encoding when mode is "text"

---

#### Python

```python Write text to file
instance.file(command="write", path="my_file.txt", content="Hello world")
```

#### TypeScript

```typescript Write text to file
await instance.file({command: "write", path: "my_file.txt", content: "Hello world"});
```

#### `append`

Append content to an existing file or create it if it doesn't exist

**`path`** `string` — required

Path to the file to append to

---

**`content`** `string` — required

Content to append to the file

---

**`mode`** `string` — default: text

Append mode: "text" or "binary" (base64 encoded for binary)

---

**`encoding`** `string` — default: utf-8

Text encoding when mode is "text"

---

#### Python

```python Append text
instance.file(command="append", path="my_file.txt", content="New content")
```

#### TypeScript

```typescript Append text
await instance.file({command: "append", path: "my_file.txt", content: "New content"});
```

#### `exists`

Check if a path exists

**`path`** `string` — required

Path to check

---

#### Python

```python Check if file exists
exists = instance.file(command="exists", path="my_file.txt")
```

#### TypeScript

```typescript Check if file exists
const exists = await instance.file({command: "exists", path: "my_file.txt"});
```

#### `list`

List the contents of a directory

**`path`** `string` — required

Path to the directory to list

---

#### Python

```python List directory contents
files = instance.file(command="list", path="my_directory")
```

#### TypeScript

```typescript List directory contents
const files = await instance.file({command: "list", path: "my_directory"});
```

#### `mkdir`

Create a directory, including parent directories if needed

**`path`** `string` — required

Path to the directory to create

---

#### Python

```python Create directory
instance.file(command="mkdir", path="new_directory")
```

#### TypeScript

```typescript Create directory
await instance.file({command: "mkdir", path: "new_directory"});
```

#### `rmdir`

Remove an empty directory

**`path`** `string` — required

Path to the directory to remove

---

#### Python

```python Remove directory
instance.file(command="rmdir", path="empty_directory")
```

#### TypeScript

```typescript Remove directory
await instance.file({command: "rmdir", path: "empty_directory"});
```

#### `delete`

Delete a file or directory

**`path`** `string` — required

Path to delete

---

**`recursive`** `boolean` — default: false

Delete directory contents recursively

---

#### Python

```python Delete file
instance.file(command="delete", path="file.txt")
```

```python Delete directory recursively
instance.file(command="delete", path="directory", recursive=True)
```

#### TypeScript

```typescript Delete file
await instance.file({command: "delete", path: "file.txt"});
```

```typescript Delete directory recursively
await instance.file({command: "delete", path: "directory", recursive: true});
```

#### `move`

Move or rename a file or directory

**`src`** `string` — required

Source path

---

**`dst`** `string` — required

Destination path

---

#### Python

```python Move or rename
instance.file(command="move", src="old_name.txt", dst="new_name.txt")
```

#### TypeScript

```typescript Move or rename
await instance.file({command: "move", src: "old_name.txt", dst: "new_name.txt"});
```

#### `copy`

Copy a file or directory

**`src`** `string` — required

Source path

---

**`dst`** `string` — required

Destination path

---

#### Python

```python Copy file or directory
instance.file(command="copy", src="source.txt", dst="destination.txt")
```

#### TypeScript

```typescript Copy file or directory
await instance.file({command: "copy", src: "source.txt", dst: "destination.txt"});
```

#### `view`

View file content with line numbers or list directory contents

**`path`** `string` — required

Path to view

---

**`view_range`** `array`

Optional \[start, end] line range to view

---

#### Python

```python View with line numbers
content = instance.file(command="view", path="my_file.txt")
```

```python View specific line range
content = instance.file(command="view", path="my_file.txt", view_range=[10, 20])
```

#### TypeScript

```typescript View with line numbers
const content = await instance.file({command: "view", path: "my_file.txt"});
```

```typescript View specific line range
const content = await instance.file({command: "view", path: "my_file.txt", viewRange: [10, 20]});
```

#### `create`

Create a new file with the given content, failing if it already exists

**`path`** `string` — required

Path to the file to create

---

**`content`** `string` — required

Content to write to the new file

---

**`mode`** `string` — default: text

Create mode: "text" or "binary" (base64 encoded for binary)

---

**`encoding`** `string` — default: utf-8

Text encoding when mode is "text"

---

#### Python

```python Create a new file
instance.file(command="create", path="new_file.txt", content="New file content")
```

#### TypeScript

```typescript Create a new file
await instance.file({command: "create", path: "new_file.txt", content: "New file content"});
```

#### `replace`

Replace a string in a file

**`path`** `string` — required

Path to the file

---

**`old_str`** `string` — required

String to replace

---

**`new_str`** `string` — required

Replacement string

---

**`all_occurrences`** `boolean` — default: false

Replace all occurrences if true, only first occurrence if false

---

#### Python

```python Replace first occurrence
instance.file(command="replace", path="my_file.txt", old_str="old text", new_str="new text")
```

```python Replace all occurrences
instance.file(command="replace", path="my_file.txt", old_str="old text", new_str="new text", all_occurrences=True)
```

#### TypeScript

```typescript Replace first occurrence
await instance.file({command: "replace", path: "my_file.txt", oldStr: "old text", newStr: "new text"});
```

```typescript Replace all occurrences
await instance.file({command: "replace", path: "my_file.txt", oldStr: "old text", newStr: "new text", allOccurrences: true});
```

#### `insert`

Insert text at a specific line in a file

**`path`** `string` — required

Path to the file

---

**`line`** `number` — required

Line number to insert at (1-based)

---

**`text`** `string` — required

Text to insert

---

#### Python

```python Insert at line
instance.file(command="insert", path="my_file.txt", line=2, text="New line content")
```

#### TypeScript

```typescript Insert at line
await instance.file({command: "insert", path: "my_file.txt", line: 2, text: "New line content"});
```

#### `delete_lines`

Delete specified lines from a file

**`path`** `string` — required

Path to the file

---

**`lines`** `array` — required

Array of line numbers to delete (1-based)

---

#### Python

```python Delete specific lines
instance.file(command="delete_lines", path="my_file.txt", lines=[2, 5, 10])
```

#### TypeScript

```typescript Delete specific lines
await instance.file({command: "delete_lines", path: "my_file.txt", lines: [2, 5, 10]});
```

#### `undo`

Undo the last text editing operation on a file

**`path`** `string` — required

Path to the file

---

#### Python

```python Undo last edit
instance.file(command="undo", path="my_file.txt")
```

#### TypeScript

```typescript Undo last edit
await instance.file({command: "undo", path: "my_file.txt"});
```

#### `grep`

Search for a pattern in a file or directory

**`pattern`** `string` — required

Regular expression pattern to search for

---

**`path`** `string` — required

Path to file or directory to search

---

**`case_sensitive`** `boolean` — default: true

Whether search is case sensitive

---

**`recursive`** `boolean` — default: false

Search directories recursively (required for directory paths)

---

**`line_numbers`** `boolean` — default: true

Include line numbers in results

---

#### Python

```python Search in file
results = instance.file(command="grep", path="my_file.txt", pattern="search term")
```

```python Recursive search in directory
results = instance.file(command="grep", path="my_directory", pattern="search term", 
                            recursive=True, case_sensitive=False)
```

#### TypeScript

```typescript Search in file
const results = await instance.file({command: "grep", path: "my_file.txt", pattern: "search term"});
```

```typescript Recursive search in directory
const results = await instance.file({command: "grep", path: "my_directory", pattern: "search term", 
                                        recursive: true, caseSensitive: false});
```

### `upload`

Upload a file to the instance

**`file`** `File` — required

The file to upload, can be a file object, bytes, or string

---

**`path`** `string` — required

Destination path on the instance

---

#### Python

```python
# Upload a file from local path
with open("local_file.txt", "rb") as f:
    response = instance.upload(file=f, path="uploaded_file.txt")

# Upload string content as a file
instance.upload(file="Hello World", path="hello.txt")

# Upload with explicit filename and content type
instance.upload(
    file=("myfile.txt", "File content", "text/plain"),
    path="myfile.txt"
)
```

#### TypeScript

```typescript
// Upload a file
const file = new File(["file content"], "filename.txt", { type: "text/plain" });
const response = await instance.upload(file, { path: "uploaded_file.txt" });

// Upload a Blob
const blob = new Blob(["Hello World"], { type: "text/plain" });
await instance.upload(blob, { path: "hello.txt" });
```

### `stop`

Stop the instance

#### Python

`python instance.stop() `

#### TypeScript

`typescript await instance.stop(); `

### `pause`

Pause the instance

#### Python

`python instance.pause() `

#### TypeScript

`typescript await instance.pause(); `

### `resume`

Resume the instance

#### Python

```python Resume with default timeout
instance.resume()
```

```python Resume with custom timeout
instance.resume(timeout_hours=2.5)
```

#### TypeScript

```typescript Resume with default timeout
await instance.resume();
```

```typescript Resume with custom timeout
await instance.resume({timeoutHours: 2.5});
```

## Compatible tools

* `BashTool`
* `ComputerTool`
* `EditTool`

## Screen resolution

By default, the Ubuntu instance runs at 1024x768 resolution. You can specify a custom resolution when starting the instance:

#### Python

```python
instance = client.start_ubuntu(resolution=[1920, 1080])
```

#### TypeScript

```typescript
const instance = await client.startUbuntu({resolution: [1920, 1080]});
```

## Additional protocols

The Ubuntu instance supports several protocols that provide additional functionality:

* [Browser](/protocols/browser) - Control the browser with Playwright
* [Code Execution](/protocols/code) - Execute code in Python and JavaScript
* [Environment Variables](/protocols/env) - Manage environment variables