Skip to content

tinker_cookbook.sandbox.ModalSandboxPool

class tinker_cookbook.sandbox.ModalSandboxPool()

Pool of Modal sandboxes for concurrent execution.

Each sandbox handles one request at a time. The pool manages borrowing and returning sandboxes automatically.

Configuration via environment variables: MODAL_POOL_SIZE: Number of sandboxes in the pool (default: 32) MODAL_CREATION_RATE_LIMIT: Max sandboxes created per second (default: 4)

run_in_workdir(files, command, timeout)

Execute command with files using an available sandbox from the pool. If all sandboxes are busy, waits until one becomes available.

Creates an isolated workdir, writes files, and runs the command.

Parameters:

  • files (dict[str, str]) – Files to write {filename: content}
  • command (list[str]) – Command and arguments (e.g., ["python", "run.py"])
  • timeout (int | None) – Execution timeout in seconds

Returns: SandboxResult

terminate()

Exit the pool and terminate all sandboxes.

Returns: None