Modal

Run an agent's commands and files in a Modal sandbox (Python).

Python only. Modal is not available in TypeScript yet: Modal's JavaScript SDK sends commands over a connection threads can't safely wrap, so modal() from @threads/modal throws ConfigError transport_fence_unsupported.

Modal runs each sandbox as a container from an image you built. Set MODAL_TOKEN_ID and MODAL_TOKEN_SECRET and pass the image id.

Python
from threads import agent
from threads.modal import modal

worker = agent(
    name="worker",
    model=model,
    sandbox=modal(image_id="im-abc123", lifetime_ms=30 * 60_000),
)

image_id is a built Modal image (im-...). Build it once at setup, for example with modal.Image.debian_slim().build(app). The image needs /bin/sh and the GNU tools sed, find, stat and sha256sum.

Options

OptionDefaultWhat it does
image_idrequiredThe built Modal image new sandboxes start from.
token_id, token_secretMODAL_TOKEN_ID, MODAL_TOKEN_SECRETAuthenticate threads' calls to Modal. Never enter the sandbox.
app_name"threads"The Modal app sandboxes run under.
environmentyour defaultThe Modal environment.
lifetime_ms1 hourHow long a sandbox lives, from 1 second to 24 hours.
allow_internetFalseOpens the network. Also set egress="unenforced" on the agent.

Good to know

  • No fork points yet. threads doesn't take Modal snapshots today, so a Modal thread can't be forked at a sandbox state.
  • Crashes park. If the host crashes mid-command, threads can't prove the command stopped, so the run parks for you instead of re-running it.

See Sandboxes for the tools an agent gets and how internet access works.

Edit on GitHub

On this page