Best Practices

Best practices for using Scrapybara

Manage instance usage

Instances are billed per usage. When launching an instance, you can specify its timeout before it is automatically terminated (default is 1 hour).

1instance = client.start(timeout=3) # 3 hours

To save costs, pause the instance to resume it later, or stop the instance once you no longer need to control the desktop environment and access its stored data.

Pause/resume
1instance.pause()
2instance.resume()
Stop
1instance.stop()

Take actions programmatically

When possible, take actions programmatically rather than relying on the agent to do so. For example, using instance.bash() provides a faster way to launch apps compared to having the model use mouse/keyboard interactions. If you know the agent’s workflow will happen on a specific application, you can launch it before prompting the agent to take actions. The same applies for browser automation: it is often easier to manipulate the browser programmatically with instance.browser and Playwright than relying on the agent itself.

Initialize the browser

For agents requiring programmatic browser interaction, initialize and configure the browser immediately after instance creation. This ensures the browser environment is ready before any browser tool calls are made.

1instance = client.start()
2instance.browser.start()
3instance.browser.authenticate(auth_state_id="auth_state_id")

Optimize your prompt

We recommend using our provided SYSTEM_PROMPT for most general-purpose computer tasks.

1from scrapybara.prompts import SYSTEM_PROMPT

However, it may be suboptimal for any specific use case. Here are some tips from Anthropic to improve the agent’s performance:

  1. Specify simple, well-defined tasks and provide explicit instructions for each step.
  2. Claude sometimes assumes outcomes of its actions without explicitly checking their results. To prevent this you can prompt Claude with After each step, take a screenshot and carefully evaluate if you have achieved the right outcome. Explicitly show your thinking: "I have evaluated step X..." If not correct, try again. Only when you confirm a step was executed correctly should you move on to the next one.
  3. Some UI elements (like dropdowns and scrollbars) might be tricky for Claude to manipulate using mouse movements. If you experience this, try prompting the model to use keyboard shortcuts.
  4. For repeatable tasks or UI interactions, include example screenshots and tool calls of successful outcomes in your prompt.
  5. If you need the model to log in, provide it with the username and password in your prompt inside xml tags like <robot_credentials>. Using computer use within applications that require login increases the risk of bad outcomes as a result of prompt injection.
Built with