Run Claude Code in a Modal Sandbox
This example demonstrates how to run Claude Code in a Modal Sandbox to analyze a GitHub repository. The Sandbox provides an isolated environment where the agent can safely execute code and examine files.
First, we create a custom Image that has Claude Code and git installed.
Then we create our Sandbox.
Next we’ll clone the repository that Claude Code will work on. We’ll use the Modal examples repo that this example is a part of.
We trigger the clone by executing git as a process inside the Sandbox. We then .wait for it to finish.
You can read more about the interface for managing ContainerProcesses in Sandboxes here.
Finally we’ll use exec again to run Claude Code to analyze the repository.
Here, we pass the pty flag to give the process a pseudo-terminal.
Once the command finishes, we read the stdout and stderr.