Overview
| Method | Description |
|---|
Sandbox.create() | Create a new sandbox |
sandbox.commands.run(cmd) | Run a command |
sandbox.code.run(code) | Run Python code |
sandbox.close() | Shut down the running sandbox (suspended instances are unaffected) |
sandbox.suspend() | Suspend to disk, returns an instance ID |
Sandbox.resume(id) | Resume a suspended instance |
Sandbox.list_instances() | List all instances |
Sandbox.destroy(id) | Delete a suspended instance from disk |
Shell commands and Python code share the same filesystem:
from vpod import Sandbox
with Sandbox.create() as sandbox:
sandbox.commands.run("echo 'from shell' > /tmp/shared.txt")
sandbox.code.run("print(open('/tmp/shared.txt').read().strip())")
Environment variables don’t cross between shell and Python: sandbox.commands.run("export FOO=bar") is not visible in sandbox.code.run(...). Use the filesystem to share data between the two.
Sandbox.create() parameters
snapshot
The snapshot to boot from. Defaults to alpine. See Snapshots for the full catalog.
sandbox = Sandbox.create(snapshot="alpine")
mounts
Mount host directories into the sandbox. Paths are read-only by default; append :rw for read-write access.
sandbox = Sandbox.create(mounts={"workspace": "/workspace:rw", "docs": "/docs"})