Documentation
Python SDK reference
Classes, methods, fields, and return types for syva.
Model
| Name | Type | Description |
|---|---|---|
Sandbox | class | Sandbox instance returned by create, get, and list. |
Image | class | Immutable image recipe used as a sandbox image input. |
sandbox.process | SandboxProcessNamespace | Foreground and background command namespace. |
sandbox.fs | SandboxFilesystemNamespace | Absolute-path filesystem namespace. |
classclassSandboxProcessNamespaceSandboxFilesystemNamespaceCreate Sandboxes
Sandbox Object
| Name | Type | Description |
|---|---|---|
id | str | Sandbox id. |
state | str | Lifecycle state. |
image | str | Resolved image ref. |
resources | dict[str, int] | Allocated CPU, memory, and disk. |
network_policy | str | Outbound network policy. |
labels | list[str] | Labels attached at creation. |
ports | list[dict] | Declared port bindings and preview URLs. |
created_at | str | ISO timestamp. |
expires_at | str | None | ISO timestamp when an expiry was requested. |
error | str | None | Terminal error when present. |
name | str | None | Unique sandbox name when assigned. |
persistent | bool | Whether stop snapshots the filesystem. |
current_snapshot_id | str | None | Snapshot the next start resumes from. |
last_snapshot | Snapshot | None | Snapshot captured by the most recent stop(). |
fs | SandboxFilesystemNamespace | Filesystem namespace. |
process | SandboxProcessNamespace | Command namespace. |
strstrstrdict[str, int]strlist[str]list[dict]strstr | Nonestr | Nonestr | Noneboolstr | NoneSnapshot | NoneSandboxFilesystemNamespaceSandboxProcessNamespaceSandbox.configure(...)Sets default base URL, API key, timeouts, and create retry settings.
Returns: None
Sandbox.create(...)Creates a sandbox and waits for it to become ready or fail.
Returns: Sandbox
Sandbox.get(sandbox_id, ...)Fetches an existing sandbox.
Returns: Sandbox
Sandbox.list(...)Lists sandboxes for the API key.
Returns: list[Sandbox]
sandbox.refresh()Reloads sandbox state.
Returns: Sandbox
Sandbox.get_by_name(name, ...)Fetches a sandbox by its unique name.
Returns: Sandbox
Sandbox.get_or_create(name=..., ...)Resumes the named sandbox, or creates it when missing.
Returns: Sandbox
sandbox.destroy()Permanently deletes the sandbox, its snapshots, and frees its name.
Returns: Sandbox
sandbox.stop()Stops the sandbox; persistent sandboxes snapshot their filesystem first.
Returns: Sandbox
sandbox.start()Resumes a stopped persistent sandbox from its latest snapshot.
Returns: Sandbox
sandbox.snapshot(expiration_seconds=None)Takes a manual snapshot; the sandbox stops.
Returns: Snapshot | None
sandbox.snapshots()Lists this sandbox's live snapshots.
Returns: list[Snapshot]
sandbox.fork(name=None, persistent=True)Creates a new sandbox from this sandbox's latest snapshot.
Returns: Sandbox
sandbox.update(...)Updates persistence, expiration, retention, or rolls back via current_snapshot_id.
Returns: Sandbox
sandbox.kill()Alias for destroy.
Returns: Sandbox
sandbox.extend_ttl(ttl_seconds=None, extend_seconds=None)Sets or extends the expiry window.
Returns: Sandbox
sandbox.extend_timeout(duration_ms)Extends the expiry window by milliseconds.
Returns: Sandbox
sandbox.wait(state="ready", timeout_ms=30000, poll_ms=100)Polls until the sandbox reaches a lifecycle state.
Returns: Sandbox
sandbox.domain(port)Returns the preview URL for an exposed port.
Returns: str
Snapshots
Persistent sandboxes snapshot their filesystem on stop() and resume with start(). See the Snapshots guide.
| Name | Type | Description |
|---|---|---|
id | str | Snapshot id. |
state | str | created, deleted, or failed. |
source | str | auto (taken on stop) or manual. |
sandbox_id | str | None | Owning sandbox. |
size_bytes | int | Stored (compressed) bytes; the billing basis. |
expires_at | str | None | Expiry, refreshed each time the snapshot is used. |
strstrstrstr | Noneintstr | NoneCommands
sandbox.run_command(command, ...)Runs a command. Set detached=True to return immediately.
Returns: CommandFinished | Command
sandbox.process.exec(command, ...)Runs a foreground command.
Returns: CommandFinished
sandbox.process.start(command, ...)Starts a background command.
Returns: Command
sandbox.process.get(process_id)Fetches the latest command state.
Returns: Command
sandbox.process.output(process_id)Returns stdout and stderr snapshot.
Returns: CommandOutput
sandbox.process.logs(process_id, stream="both")Returns stdout, stderr, or combined log text.
Returns: str
sandbox.process.stream(process_id, ...)Streams stdout, stderr, and final status events.
Returns: Iterator[CommandOutputEvent]
sandbox.process.stop(process_id)Stops a running command.
Returns: Command
sandbox.process.wait(process_id, ...)Waits for command completion.
Returns: Command
sandbox.process.list(limit=100)Lists recent commands.
Returns: list[Command]
command.read_logs(stream="both")Returns stdout, stderr, or combined log text.
Returns: str
sandbox.get_command(command_id)Fetches a command through the sandbox helper.
Returns: Command
sandbox.list_commands(limit=100)Lists commands through the sandbox helper.
Returns: list[Command]
CommandFinished
| Name | Type | Description |
|---|---|---|
exit_code | int | Process exit code. |
stdout | str | Captured stdout. |
stderr | str | Captured stderr. |
duration_ms | int | Runtime duration. |
timed_out | bool | True when the timeout killed the command. |
intstrstrintboolFilesystem
Top-level helpers default to /workspace. sandbox.fs uses absolute paths.
sandbox.write_file(path, data, ...)Writes under /workspace unless path is absolute.
Returns: None
sandbox.write_files(files, ...)Writes multiple files under /workspace unless paths are absolute.
Returns: None
sandbox.read_file(path, ...)Reads bytes, or None when missing.
Returns: bytes | None
sandbox.mkdir(path, ...)Creates a directory under /workspace unless path is absolute.
Returns: FileInfo
sandbox.mk_dir(path, ...)Alias for sandbox.mkdir().
Returns: FileInfo
sandbox.fs.write(path, data, ...)Writes bytes or text to an absolute path.
Returns: None
sandbox.fs.write_file(path, data, ...)Alias for sandbox.fs.write().
Returns: None
sandbox.fs.write_files(files, ...)Writes multiple absolute-path files.
Returns: None
sandbox.fs.read(path)Reads bytes from an absolute path.
Returns: bytes
sandbox.fs.read_file(path)Alias for sandbox.fs.read().
Returns: bytes
sandbox.fs.stat(path)Returns path metadata.
Returns: FileInfo
sandbox.fs.list(path)Lists directory entries.
Returns: list[FileInfo]
sandbox.fs.find(path="/", ...)Finds files and directories by type or pattern.
Returns: list[FileInfo]
sandbox.fs.grep(query, path="/", ...)Searches file contents and returns matching lines.
Returns: list[GrepMatch]
sandbox.fs.mkdir(path, ...)Creates a directory.
Returns: FileInfo
sandbox.fs.rm(path, ...)Removes a file or directory.
Returns: None
Images
String images are Syva image refs. Public registry refs such as node:22 should be wrapped with Image.from_registry; Sandbox.create builds that recipe into a reusable Syva image before launch.
Image recipes are immutable. Every mutating method returns a new Image.
Image()Creates a base image recipe from a Syva base ref.
Returns: Image
Image.from_registry(image, add_python=None)Starts a recipe from a public Docker or OCI registry image.
Returns: Image
Image.syva_base()Starts from the Syva base image.
Returns: Image
image.python(version="3.12")Adds Python tooling.
Returns: Image
image.apt_install(packages)Installs Debian packages.
Returns: Image
image.pip_install(packages, user=False)Installs Python packages.
Returns: Image
image.npm_install(packages=None, global_=False)Installs npm packages.
Returns: Image
image.run_cmd(commands, user=None)Adds build-time shell commands.
Returns: Image
image.env(**values)Adds default environment variables.
Returns: Image
image.workdir(path)Sets the default workdir.
Returns: Image
image.user(user)Sets the default user.
Returns: Image
image.copy(src, dest, ...)Copies files into the build context.
Returns: Image
image.set_start_cmd(command, ready_command=None)Sets boot and optional readiness commands.
Returns: Image
image.digest()Returns a stable recipe digest.
Returns: str
Errors
| Name | Type | Description |
|---|---|---|
message | str | Human-readable error. |
code | str | None | Stable Syva error code. |
status | int | None | HTTP status when available. |
sandbox_id | str | None | Related sandbox id when available. |
retryable | bool | None | Whether retrying may succeed. |
strstr | Noneint | Nonestr | Nonebool | None