> 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.

# Code Execution

#### Python

#### Start an instance

```python
from scrapybara import Scrapybara

client = Scrapybara(api_key="your_api_key")
instance = client.start_ubuntu()
```

#### Execute code directly

```python
result = instance.code.execute(
    code="print('Hello from Scrapybara!')",
    kernel_name="python3"  # Optional: specify kernel
)
```

#### List available kernels

```python
kernels = instance.notebook.list_kernels()
```

#### Create a notebook

```python
notebook = instance.notebook.create(
    name="my_notebook",
    kernel_name="python3"
)
```

#### Add and execute cells

```python
# Add a code cell
cell = instance.notebook.add_cell(
    notebook_id=notebook.id,
    type="code",
    content="print('Hello from Scrapybara!')"
)

# Execute the cell
result = instance.notebook.execute_cell(
    notebook_id=notebook.id,
    cell_id=cell.id
)
```

#### Execute entire notebook

```python
# Execute all cells in the notebook
results = instance.notebook.execute(notebook_id=notebook.id)
```

#### Clean up

```python
# Delete the notebook when done
instance.notebook.delete(notebook_id=notebook.id)
```

#### TypeScript

#### Start an instance

```typescript
import { ScrapybaraClient } from "scrapybara";

const client = new ScrapybaraClient({ apiKey: "your_api_key" });
const instance = await client.startUbuntu();
```

#### Execute code directly

```typescript
const result = await instance.code.execute({
    code: "print('Hello from Scrapybara!')",
    kernelName: "python3"  // Optional: specify kernel
});
```

#### List available kernels

```typescript
const kernels = await instance.notebook.listKernels();
```

#### Create a notebook

```typescript
const notebook = await instance.notebook.create({
    name: "my_notebook",
    kernelName: "python3"
});
```

#### Add and execute cells

```typescript
// Add a code cell
const cell = await instance.notebook.addCell({
    notebookId: notebook.id,
    type: "code",
    content: "print('Hello from Scrapybara!')"
});

// Execute the cell
const result = await instance.notebook.executeCell({
    notebookId: notebook.id,
    cellId: cell.id
});
```

#### Execute entire notebook

```typescript
// Execute all cells in the notebook
const results = await instance.notebook.execute({
    notebookId: notebook.id
});
```

#### Clean up

```typescript
// Delete the notebook when done
await instance.notebook.delete({
    notebookId: notebook.id
});
```