Skip to content

tinker_cookbook.sandbox.ModalSandbox

class tinker_cookbook.sandbox.ModalSandbox()

Persistent Modal sandbox for code execution. Conforms to SandboxInterface.

Usage: sandbox = await ModalSandbox.create()

await sandbox.write_file("/workspace/code.py", "print('hello')") result = await sandbox.run_command("python /workspace/code.py") print(result.stdout)

await sandbox.cleanup()

create(app_name, timeout, image, max_stream_output_bytes)

Create a new Modal sandbox.

Parameters:

Returns: ModalSandbox

run_command(command, workdir, timeout, max_output_bytes)

Run a shell command in the sandbox.

Parameters:

Returns: SandboxResult

read_file(path, max_bytes, timeout)

Read a file from the sandbox.

Parameters:

Returns: SandboxResult

write_file(path, content, executable, timeout)

Write content to a file in the sandbox.

Parameters:

Returns: SandboxResult

cleanup()

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

Returns: None