Skip to main content

Anthropic Computer Use on Modal

Anthropic's recent release of Computer Use is fantastic, but spinning up random Docker images didn't fit into our production workflow. Luckily, we use Modal and they have all the primitives we need to implement the Computer Use API.

If you're curious about why this library exists, check out this blog post.

This library provides an out-of-the-box implementation that can be deployed into your Modal environment. Everything runs in a Sandbox, with tool calls being translated into Modal API calls. It may or may not spectacularly explode. It's also quite slow at the moment. Caveat emptor!

Features

  • Deploys into its own app that can be called from your existing apps
  • Sandboxes scale to zero and are resumable
  • VNC tunnel to each sandbox for debugging
  • One NFS per sandbox, available for inspection
  • Image processing outside the sandbox, greatly speeding up screenshot generation
  • Fuzzy matching for the Edit tool, since the model often misses a newline or two
  • Hardware-accelerated browsing in the sandbox
  • Pre-warming of the sandbox for faster startup times
  • Tools for the LLM to work faster, such as apt-fast

Installation

You can install this library without cloning the repo by running:

pip install computer-use-modal

To use it in your own project, simply deploy it once:

modal deploy computer_use_modal

Then you can use it in your app like this:

from modal import Cls

server = Cls.lookup("anthropic-computer-use-modal", "ComputerUseServer")
response = server.messages_create.remote.aio(
    request_id=uuid4().hex,
    user_messages=[{"role": "user", "content": "What is the weather in San Francisco?"}],
)
print(response)
{
    "role": "assistant",
    "content": [
        BetaTextBlock(
            text="According to the National Weather Service, the current weather in San Francisco is:\n\nTemperature: 65°F (18°C)\nHumidity: 53%\nDewpoint: 48°F (9°C)\nLast update: October 23, 2:43 PM PDT\n\nThe website shows the forecast details as well. Would you like me to provide the extended forecast for the coming days?",
            type="text",
        )
    ]
}

You can also watch the progress with a VNC tunnel:

manager = Cls.lookup("anthropic-computer-use-modal", "SandboxManager")
urls = manager.debug_urls.remote()
print(urls["vnc"])
"https://x2xzanmu4yg.r9.modal.host"

If you want to stream the responses, you can use ComputerUseServer.messages_create_gen.

Demo

You can clone this repo and run two demos locally.

CLI Demo

This demo will deploy an ephemeral Modal app, and ask the LLM to browse the web to fetch the weather in San Francisco. Screenshots will be shown in your terminal so you can follow along!

git clone https://github.com/yasyf/anthropic-tool-use-modal
cd anthropic-tool-use-modal
uv sync
modal run computer_use_modal.demo

Streamlit Demo

This demo deploys the app persistently to its own namespace in your Modal account, then starts a Streamlit app that can interact with it.

git clone https://github.com/yasyf/anthropic-tool-use-modal
cd anthropic-tool-use-modal
uv sync --dev
modal deploy computer_use_modal
python -m streamlit run computer_use_modal/streamlit.py

Streamlit Demo

Thanks

Thanks to the Anthropic team for the awesome starting point!

Metadata

Release files for computer-use-modal 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for computer-use-modal 0.1.2
File Size Uploaded Provenance
computer_use_modal-0.1.2.tar.gz 21.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for computer-use-modal 0.1.2
File Interpreter ABI Platform
computer_use_modal-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 49.4 kB

Release files / computer_use_modal-0.1.2.tar.gz

Download URL computer_use_modal-0.1.2.tar.gz
Size 21.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ef22e0660e65e82343fab97a7e8fea9e0c52081c86b44eec08c7337aaa7d3c3b
BLAKE2b-256 checksum
How to use checksums
424c0457f1f3ab5d0f84a3a0873477cf845ea10140e485fc0ec6652e04d8de14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.4.26

Release files / computer_use_modal-0.1.2-py3-none-any.whl

Download URL computer_use_modal-0.1.2-py3-none-any.whl
Size 27.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a758887ba9fc1839a645b470ae930f78ac4a1116daa45db520508751e7aff6e0
BLAKE2b-256 checksum
How to use checksums
d16ef921363ffc80f5ccdf8a5c914c6edfc065483c74516dc6a15e6ddf612c2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.4.26

Security for computer-use-modal 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page