For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DiscordDashboard
DocumentationAPI ReferenceCookbook
DocumentationAPI ReferenceCookbook
  • Get Started
    • Introduction
    • Quickstart
    • Best Practices
  • Guides
    • Act SDK
    • Auth States
    • Conversations
    • Tools
  • Providers
    • OpenAI
    • Anthropic
  • Instances
    • Ubuntu
      • Browser
      • Code Execution
      • Environment Variables
    • Browser
    • Windows
  • Resources
    • Starter Templates
    • Cursor Rules
    • Cookbook
Logo
DiscordDashboard
InstancesUbuntu

Code Execution

Execute code in your Scrapybara instance
Was this page helpful?
Previous

Environment Variables

Manage environment variables in your Scrapybara instance
Next
Built with
Python
TypeScript
1

Start an instance

1from scrapybara import Scrapybara
2
3client = Scrapybara(api_key="your_api_key")
4instance = client.start_ubuntu()
2

Execute code directly

1result = instance.code.execute(
2 code="print('Hello from Scrapybara!')",
3 kernel_name="python3" # Optional: specify kernel
4)
3

List available kernels

1kernels = instance.notebook.list_kernels()
4

Create a notebook

1notebook = instance.notebook.create(
2 name="my_notebook",
3 kernel_name="python3"
4)
5

Add and execute cells

1# Add a code cell
2cell = instance.notebook.add_cell(
3 notebook_id=notebook.id,
4 type="code",
5 content="print('Hello from Scrapybara!')"
6)
7
8# Execute the cell
9result = instance.notebook.execute_cell(
10 notebook_id=notebook.id,
11 cell_id=cell.id
12)
6

Execute entire notebook

1# Execute all cells in the notebook
2results = instance.notebook.execute(notebook_id=notebook.id)
7

Clean up

1# Delete the notebook when done
2instance.notebook.delete(notebook_id=notebook.id)