ModalSandbox - Tinker Documentation
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:
- app_name ( str)
- timeout ( int)
- image ( modal.Image | None)
- max_stream_output_bytes ( int)
Returns: ModalSandbox
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)
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:
- path ( str)
- content ( str | bytes)
- executable ( bool)
- timeout ( int)
Returns: SandboxResult
cleanup()
Terminate the Modal sandbox and wait for it to fully shut down.
Returns: None