Run Anthropic’s computer use demo in a Modal Sandbox

This example demonstrates how to run Anthropic’s Computer Use demo in a Modal Sandbox.

Sandbox Setup 

All Sandboxes are associated with an App.

We start by looking up an existing App by name, or creating one if it doesn’t exist.

The Computer Use quickstart provides a prebuilt Docker image. We use this hosted image to create our sandbox environment.

We’ll provide the Anthropic API key via a Modal Secret which the sandbox can access at runtime.

Now, we can start our Sandbox. We use modal.enable_output() to print the Sandbox’s image build logs to the console. We’ll also expose the ports required for the demo’s interfaces:

  • Port 8501 serves the Streamlit UI for interacting with the agent loop
  • Port 6080 serves the VNC desktop view via a browser-based noVNC client

After starting the sandbox, we retrieve the public URLs for the exposed ports.

We can check on each server’s status by making an HTTP request to the server’s URL and verifying that it responds with a 200 status code.

You can now open the URLs in your browser to interact with the demo! Note: The sandbox logs may mention localhost:8080. Ignore this and use the printed tunnel URLs instead.

When finished, you can terminate the sandbox from your Modal dashboard or by running Sandbox.from_id(sandbox.object_id).terminate(). The Sandbox will also spin down after one hour.