Skip to content

tinker_cookbook.sandbox.ModalSandbox

class tinker_cookbook.sandbox.ModalSandbox(**)

Persistent Modal sandbox for code execution. Conforms to SandboxInterface.

create(app_name, timeout, image, max_stream_output_bytes)

Create a new Modal sandbox.

Parameters:

  • app_name (str)
  • timeout (int)
  • image (modal.Image | None)
  • max_stream_output_bytes (int)

run_command(command, workdir, timeout, max_output_bytes)

Run a shell command in the sandbox.

Parameters:

  • command (str)
  • workdir (str | None)
  • timeout (int)
  • max_output_bytes (int | None)

read_file(path, max_bytes, timeout)

Read a file from the sandbox.

Parameters:

  • path (str)
  • max_bytes (int | None)
  • timeout (int)

write_file(path, content, executable, timeout)

Write content to a file in the sandbox.

Parameters:

  • path (str)
  • content (str | bytes)
  • executable (bool)
  • timeout (int)

cleanup()

Terminate the Modal sandbox and wait for it to fully shut down.