Skip to main content

wrenn

wrenn.client

CapsulesResource Objects

Sync capsule control-plane operations.

create

Create a new capsule. Arguments:
  • template str | None - Template name to boot from.
  • vcpus int | None - Number of virtual CPUs.
  • memory_mb int | None - Memory in MiB.
  • timeout_sec int | None - Inactivity TTL in seconds before auto-pause. 0 disables auto-pause.
Returns:
  • CapsuleModel - The newly created capsule.

list

List all capsules for the authenticated team. Returns:
  • list[CapsuleModel] - All capsules belonging to the team.

get

Get a capsule by ID. Arguments:
  • id str - Capsule ID.
Returns:
  • CapsuleModel - Current state of the capsule.
Raises:
  • WrennNotFoundError - If no capsule with the given ID exists.

destroy

Destroy a capsule permanently. Arguments:
  • id str - Capsule ID.
Raises:
  • WrennNotFoundError - If no capsule with the given ID exists.

pause

Pause a running capsule. Arguments:
  • id str - Capsule ID.
Returns:
  • CapsuleModel - Updated capsule state.
Raises:
  • WrennNotFoundError - If no capsule with the given ID exists.

resume

Resume a paused capsule. Arguments:
  • id str - Capsule ID.
Returns:
  • CapsuleModel - Updated capsule state.
Raises:
  • WrennNotFoundError - If no capsule with the given ID exists.

ping

Reset the inactivity timer for a capsule. Arguments:
  • id str - Capsule ID.
Raises:
  • WrennNotFoundError - If no capsule with the given ID exists.

AsyncCapsulesResource Objects

Async capsule control-plane operations.

create

Create a new capsule. Arguments:
  • template str | None - Template name to boot from.
  • vcpus int | None - Number of virtual CPUs.
  • memory_mb int | None - Memory in MiB.
  • timeout_sec int | None - Inactivity TTL in seconds before auto-pause. 0 disables auto-pause.
Returns:
  • CapsuleModel - The newly created capsule.

list

List all capsules for the authenticated team. Returns:
  • list[CapsuleModel] - All capsules belonging to the team.

get

Get a capsule by ID. Arguments:
  • id str - Capsule ID.
Returns:
  • CapsuleModel - Current state of the capsule.
Raises:
  • WrennNotFoundError - If no capsule with the given ID exists.

destroy

Destroy a capsule permanently. Arguments:
  • id str - Capsule ID.
Raises:
  • WrennNotFoundError - If no capsule with the given ID exists.

pause

Pause a running capsule. Arguments:
  • id str - Capsule ID.
Returns:
  • CapsuleModel - Updated capsule state.
Raises:
  • WrennNotFoundError - If no capsule with the given ID exists.

resume

Resume a paused capsule. Arguments:
  • id str - Capsule ID.
Returns:
  • CapsuleModel - Updated capsule state.
Raises:
  • WrennNotFoundError - If no capsule with the given ID exists.

ping

Reset the inactivity timer for a capsule. Arguments:
  • id str - Capsule ID.
Raises:
  • WrennNotFoundError - If no capsule with the given ID exists.

SnapshotsResource Objects

Sync snapshot operations.

create

Create a snapshot template from a running capsule. Arguments:
  • capsule_id str - ID of the capsule to snapshot.
  • name str | None - Name for the snapshot template. Auto-generated if not provided.
  • overwrite bool - If True, overwrite an existing template with the same name. Defaults to False.
Returns:
  • Template - The created snapshot template.

list

List snapshot templates. Arguments:
  • type str | None - Filter by template type. Returns all templates if not provided.
Returns:
  • list[Template] - Matching snapshot templates.

delete

Delete a snapshot template by name. Arguments:
  • name str - Template name to delete.
Raises:
  • WrennNotFoundError - If no template with the given name exists.

AsyncSnapshotsResource Objects

Async snapshot operations.

create

Create a snapshot template from a running capsule. Arguments:
  • capsule_id str - ID of the capsule to snapshot.
  • name str | None - Name for the snapshot template. Auto-generated if not provided.
  • overwrite bool - If True, overwrite an existing template with the same name. Defaults to False.
Returns:
  • Template - The created snapshot template.

list

List snapshot templates. Arguments:
  • type str | None - Filter by template type. Returns all templates if not provided.
Returns:
  • list[Template] - Matching snapshot templates.

delete

Delete a snapshot template by name. Arguments:
  • name str - Template name to delete.
Raises:
  • WrennNotFoundError - If no template with the given name exists.

WrennClient Objects

Synchronous client for the Wrenn API. Authenticates with an API key. Arguments:
  • api_key - API key (wrn_...). Falls back to WRENN_API_KEY env var.
  • base_url - Wrenn API base URL.

http

The underlying httpx.Client (for sub-objects that need direct access).

close

Close the underlying HTTP connection pool.

AsyncWrennClient Objects

Asynchronous client for the Wrenn API. Authenticates with an API key. Arguments:
  • api_key - API key (wrn_...). Falls back to WRENN_API_KEY env var.
  • base_url - Wrenn API base URL. Falls back to WRENN_BASE_URL env var.

http

The underlying httpx.AsyncClient.

aclose

Close the underlying async HTTP connection pool.

wrenn.sandbox

wrenn.commands

CommandResult Objects

Result from a foreground command execution.

CommandHandle Objects

Handle for a background process.

ProcessInfo Objects

Information about a running process.

StreamEvent Objects

Base class for streaming exec events.

Commands Objects

Sync command execution interface. Accessed via capsule.commands.

run

Execute a shell command inside the capsule. Arguments:
  • cmd str - Shell command string to execute.
  • background bool - If True, launch the process in the background and return a :class:CommandHandle immediately. Defaults to False.
  • timeout int | None - Seconds before the foreground command times out. Ignored for background commands. Defaults to 30.
  • envs dict[str, str] | None - Additional environment variables to set for the process.
  • cwd str | None - Working directory for the process.
  • tag str | None - Optional label attached to background processes for later retrieval via :meth:connect.
Returns:
  • CommandResult - stdout, stderr, exit code, and duration for foreground commands (background=False).
  • CommandHandle - PID and tag for background commands (background=True).

list

List all running background processes in the capsule. Returns:
  • list[ProcessInfo] - Running processes with their PID, tag, and command information.

kill

Send SIGKILL to a background process. Arguments:
  • pid int - PID of the process to kill.
Raises:
  • WrennNotFoundError - If no process with the given PID exists.

connect

Connect to a running background process and stream its output. Arguments:
  • pid int - PID of the background process to attach to.
Yields:
  • StreamEvent - Successive output events. Stops on :class:StreamExitEvent or :class:StreamErrorEvent.

stream

Execute a command via WebSocket, streaming output as events. Arguments:
  • cmd str - Command to execute.
  • args list[str] | None - Additional arguments for the command. When omitted, cmd is interpreted as a shell command string and executed via /bin/sh -c.
Yields:
  • StreamEvent - Successive events including :class:StreamStartEvent, :class:StreamStdoutEvent, :class:StreamStderrEvent, :class:StreamExitEvent, and :class:StreamErrorEvent.

AsyncCommands Objects

Async command execution interface. Accessed via capsule.commands.

run

Execute a shell command inside the capsule. Arguments:
  • cmd str - Shell command string to execute.
  • background bool - If True, launch the process in the background and return a :class:CommandHandle immediately. Defaults to False.
  • timeout int | None - Seconds before the foreground command times out. Ignored for background commands. Defaults to 30.
  • envs dict[str, str] | None - Additional environment variables to set for the process.
  • cwd str | None - Working directory for the process.
  • tag str | None - Optional label attached to background processes for later retrieval via :meth:connect.
Returns:
  • CommandResult - stdout, stderr, exit code, and duration for foreground commands (background=False).
  • CommandHandle - PID and tag for background commands (background=True).

list

List all running background processes in the capsule. Returns:
  • list[ProcessInfo] - Running processes with their PID, tag, and command information.

kill

Send SIGKILL to a background process. Arguments:
  • pid int - PID of the process to kill.
Raises:
  • WrennNotFoundError - If no process with the given PID exists.

connect

Connect to a running background process and stream its output. Arguments:
  • pid int - PID of the background process to attach to.
Yields:
  • StreamEvent - Successive output events. Stops on :class:StreamExitEvent or :class:StreamErrorEvent.

stream

Execute a command via WebSocket, streaming output as events. Arguments:
  • cmd str - Command to execute.
  • args list[str] | None - Additional arguments for the command. When omitted, cmd is interpreted as a shell command string and executed via /bin/sh -c.
Yields:
  • StreamEvent - Successive events including :class:StreamStartEvent, :class:StreamStdoutEvent, :class:StreamStderrEvent, :class:StreamExitEvent, and :class:StreamErrorEvent.

wrenn.files

Files Objects

Sync filesystem interface. Accessed via capsule.files.

read

Read a file as a UTF-8 string. Arguments:
  • path str - Absolute path to the file inside the capsule.
Returns:
  • str - File contents decoded as UTF-8.
Raises:
  • WrennNotFoundError - If the path does not exist.

read_bytes

Read a file as raw bytes. Arguments:
  • path str - Absolute path to the file inside the capsule.
Returns:
  • bytes - Raw file contents.
Raises:
  • WrennNotFoundError - If the path does not exist.

write

Write data to a file inside the capsule. Creates parent directories if they do not exist. Arguments:
  • path str - Absolute destination path inside the capsule.
  • data str | bytes - Content to write. Strings are UTF-8 encoded.

list

List directory contents. Arguments:
  • path str - Absolute path to the directory inside the capsule.
  • depth int - Recursion depth. 1 lists only immediate children. Defaults to 1.
Returns:
  • list[FileEntry] - Entries in the directory.
Raises:
  • WrennNotFoundError - If the path does not exist.

exists

Check whether a path exists inside the capsule. Arguments:
  • path str - Absolute path to check.
Returns:
  • bool - True if the path exists.

make_dir

Create a directory (with parents). Idempotent. Arguments:
  • path str - Absolute path of the directory to create.
Returns:
  • FileEntry - The created (or already-existing) directory entry.

remove

Remove a file or directory recursively. Arguments:
  • path str - Absolute path to remove.
Raises:
  • WrennNotFoundError - If the path does not exist.

upload_stream

Stream a large file into the capsule. Prefer this over :meth:write when the file is too large to hold in memory. Arguments:
  • path str - Absolute destination path inside the capsule.
  • stream Iterator[bytes] - Iterable of byte chunks to upload.

download_stream

Stream a large file out of the capsule. Prefer this over :meth:read_bytes when the file is too large to hold in memory. Arguments:
  • path str - Absolute path to the file inside the capsule.
Yields:
  • bytes - Successive byte chunks of the file.
Raises:
  • WrennNotFoundError - If the path does not exist.

AsyncFiles Objects

Async filesystem interface. Accessed via capsule.files.

read

Read a file as a UTF-8 string. Arguments:
  • path str - Absolute path to the file inside the capsule.
Returns:
  • str - File contents decoded as UTF-8.
Raises:
  • WrennNotFoundError - If the path does not exist.

read_bytes

Read a file as raw bytes. Arguments:
  • path str - Absolute path to the file inside the capsule.
Returns:
  • bytes - Raw file contents.
Raises:
  • WrennNotFoundError - If the path does not exist.

write

Write data to a file inside the capsule. Creates parent directories if they do not exist. Arguments:
  • path str - Absolute destination path inside the capsule.
  • data str | bytes - Content to write. Strings are UTF-8 encoded.

list

List directory contents. Arguments:
  • path str - Absolute path to the directory inside the capsule.
  • depth int - Recursion depth. 1 lists only immediate children. Defaults to 1.
Returns:
  • list[FileEntry] - Entries in the directory.
Raises:
  • WrennNotFoundError - If the path does not exist.

exists

Check whether a path exists inside the capsule. Arguments:
  • path str - Absolute path to check.
Returns:
  • bool - True if the path exists.

make_dir

Create a directory (with parents). Idempotent. Arguments:
  • path str - Absolute path of the directory to create.
Returns:
  • FileEntry - The created (or already-existing) directory entry.

remove

Remove a file or directory recursively. Arguments:
  • path str - Absolute path to remove.
Raises:
  • WrennNotFoundError - If the path does not exist.

upload_stream

Stream a large file into the capsule. Prefer this over :meth:write when the file is too large to hold in memory. Arguments:
  • path str - Absolute destination path inside the capsule.
  • stream AsyncIterator[bytes] - Async iterable of byte chunks to upload.

download_stream

Stream a large file out of the capsule. Prefer this over :meth:read_bytes when the file is too large to hold in memory. Arguments:
  • path str - Absolute path to the file inside the capsule.
Yields:
  • bytes - Successive byte chunks of the file.
Raises:
  • WrennNotFoundError - If the path does not exist.

wrenn.code_interpreter.models

ExecutionError Objects

Error raised during code execution. Attributes:
  • name - Exception class name (e.g. "NameError").
  • value - Exception message.
  • traceback - Full traceback string.

Logs Objects

Captured stdout/stderr streams. Each element in the list is one chunk of text as it arrived from the kernel.

Result Objects

A single rich output from code execution. Jupyter cells can produce multiple outputs — one execute_result (the expression value) and zero or more display_data messages (from plt.show(), display(), etc.). Each becomes a Result. Known MIME types are unpacked into named attributes; anything else lands in :pyattr:extra.

text

text/plain representation.

html

text/html representation.

markdown

text/markdown representation.

svg

image/svg+xml representation.

png

image/png — base64-encoded.

jpeg

image/jpeg — base64-encoded.

pdf

application/pdf — base64-encoded.

latex

text/latex representation.

json

application/json representation.

javascript

application/javascript representation.

extra

MIME types not covered by the named fields above.

is_main_result

True when this came from an execute_result message (i.e. the value of the last expression in the cell). False for display_data outputs.

from_bundle

Build a Result from a Jupyter MIME bundle dict.

formats

Return names of non-None MIME-type fields.

Execution Objects

Complete result of a run_code call. Attributes:
  • results - All rich outputs produced by the cell — charts, tables, images, expression values, etc.
  • logs - Captured stdout/stderr text.
  • error - Populated when the cell raised an exception.
  • execution_count - Jupyter execution counter (the [N] number).

text

Convenience — text/plain of the main execute_result, or None if the cell had no expression value.

wrenn.code_interpreter.async_capsule

AsyncCapsule Objects

Async code interpreter capsule with run_code support. Uses code-runner-beta template by default:: from wrenn.code_interpreter import AsyncCapsule capsule = await AsyncCapsule.create() result = await capsule.run_code(“print(‘hello’)“)

create

Create a new async code interpreter capsule. Arguments:
  • template str | None - Template to boot from. Defaults to "code-runner-beta".
  • vcpus int | None - Number of virtual CPUs.
  • memory_mb int | None - Memory in MiB.
  • timeout int | None - Inactivity TTL in seconds before auto-pause.
  • wait bool - Await until the capsule reaches running status.
  • api_key str | None - Wrenn API key. Falls back to WRENN_API_KEY env var.
  • base_url str | None - API base URL override.
Returns:
  • AsyncCapsule - A new async code interpreter capsule instance.

run_code

Execute code in a persistent Jupyter kernel (async). Arguments:
  • code - Code string to execute.
  • language - Execution backend language. Currently only "python".
  • timeout - Maximum seconds to wait for execution to complete.
  • jupyter_timeout - Maximum seconds to wait for Jupyter to become available.
  • on_result - Called for each rich output (charts, images, expression values).
  • on_stdout - Called for each stdout chunk.
  • on_stderr - Called for each stderr chunk.
  • on_error - Called when the cell raises an exception.
Returns: An :class:Execution with .results, .logs, .error, and a convenience .text property.

wrenn.code_interpreter

wrenn.code_interpreter.capsule

Capsule Objects

Code interpreter capsule with run_code support. Uses code-runner-beta template by default:: from wrenn.code_interpreter import Capsule capsule = Capsule() result = capsule.run_code(“print(‘hello’)”) print(result.logs.stdout) # [“hello\n”]

__init__

Create a code interpreter capsule. Arguments:
  • template str | None - Template to boot from. Defaults to "code-runner-beta".
  • vcpus int | None - Number of virtual CPUs.
  • memory_mb int | None - Memory in MiB.
  • timeout int | None - Inactivity TTL in seconds before auto-pause.
  • api_key str | None - Wrenn API key. Falls back to WRENN_API_KEY env var.
  • base_url str | None - API base URL override.

create

Create a new code interpreter capsule. Arguments:
  • template str | None - Template to boot from. Defaults to "code-runner-beta".
  • vcpus int | None - Number of virtual CPUs.
  • memory_mb int | None - Memory in MiB.
  • timeout int | None - Inactivity TTL in seconds before auto-pause.
  • wait bool - Block until the capsule reaches running status.
  • api_key str | None - Wrenn API key. Falls back to WRENN_API_KEY env var.
  • base_url str | None - API base URL override.
Returns:
  • Capsule - A new code interpreter capsule instance.

run_code

Execute code in a persistent Jupyter kernel. Variables, imports, and function definitions survive across calls. Arguments:
  • code - Code string to execute.
  • language - Execution backend language. Currently only "python".
  • timeout - Maximum seconds to wait for execution to complete.
  • jupyter_timeout - Maximum seconds to wait for Jupyter to become available.
  • on_result - Called for each rich output (charts, images, expression values).
  • on_stdout - Called for each stdout chunk.
  • on_stderr - Called for each stderr chunk.
  • on_error - Called when the cell raises an exception.
Returns: An :class:Execution with .results, .logs, .error, and a convenience .text property.

wrenn.exceptions

WrennError Objects

Base exception for all Wrenn SDK errors. All SDK exceptions inherit from this class, so you can catch WrennError to handle any API error generically. Attributes:
  • code str - Machine-readable error code from the API (e.g. "not_found").
  • message str - Human-readable error description.
  • status_code int - HTTP status code of the response.

__init__

Initialize a WrennError. Arguments:
  • code str - Machine-readable error code.
  • message str - Human-readable error description.
  • status_code int - HTTP status code of the response.

WrennValidationError Objects

400 — Invalid request parameters.

WrennAuthenticationError Objects

401 — Invalid or missing authentication.

WrennForbiddenError Objects

403 — Authenticated but not authorized.

WrennNotFoundError Objects

404 — Resource not found.

WrennConflictError Objects

409 — State conflict (e.g. invalid_state).

WrennHostHasCapsulesError Objects

409 — Host still has running capsules. Attributes:
  • capsule_ids list[str] - IDs of the capsules still running on the host.

__init__

Initialize a WrennHostHasCapsulesError. Arguments:
  • code str - Machine-readable error code.
  • message str - Human-readable error description.
  • status_code int - HTTP status code of the response.
  • capsule_ids list[str] - IDs of capsules still on the host.

WrennHostUnavailableError Objects

503 — No suitable host available.

WrennAgentError Objects

502 — Host agent returned an error.

WrennInternalError Objects

500 — Unexpected server error.

wrenn.async_capsule

AsyncCapsule Objects

Async Wrenn capsule with e2b-compatible interface. Create via classmethod:: capsule = await AsyncCapsule.create(template=“minimal”) Use as async context manager:: async with await AsyncCapsule.create() as capsule: await capsule.commands.run(“echo hello”)

capsule_id

The capsule’s unique identifier. Returns:
  • str - Capsule ID assigned by the Wrenn API.

info

Cached capsule metadata from the last API call. Returns: CapsuleModel | None: The last-fetched capsule model, or None if the capsule was connected without an initial fetch.

create

Create a new capsule. Arguments:
  • template str | None - Template name to boot from.
  • vcpus int | None - Number of virtual CPUs.
  • memory_mb int | None - Memory in MiB.
  • timeout int | None - Inactivity TTL in seconds before auto-pause.
  • wait bool - Await until the capsule reaches running status.
  • api_key str | None - Wrenn API key. Falls back to WRENN_API_KEY env var.
  • base_url str | None - API base URL override.
Returns:
  • AsyncCapsule - A new capsule instance.

connect

Connect to an existing capsule, resuming it if paused. Arguments:
  • capsule_id str - ID of the capsule to connect to.
  • api_key str | None - Wrenn API key. Falls back to WRENN_API_KEY env var.
  • base_url str | None - API base URL override.
Returns:
  • AsyncCapsule - A capsule instance bound to the existing capsule.
Raises:
  • WrennNotFoundError - If no capsule with the given ID exists.

ping

Reset the capsule inactivity timer. Call this to prevent the capsule from being auto-paused when the inactivity TTL is set.

wait_ready

Await until the capsule status is running. Arguments:
  • timeout float - Maximum seconds to wait. Defaults to 30.
  • interval float - Polling interval in seconds. Defaults to 0.5.
Raises:
  • TimeoutError - If the capsule does not reach running state within timeout seconds.
  • RuntimeError - If the capsule enters an error, stopped, or paused state while waiting.

is_running

Check whether the capsule is currently running. Makes a live API call to fetch current status. Returns:
  • bool - True if the capsule status is running.

list

List all capsules belonging to the team. Arguments:
  • api_key str | None - Wrenn API key. Falls back to WRENN_API_KEY env var.
  • base_url str | None - API base URL override.
Returns:
  • list[CapsuleModel] - All capsules for the authenticated team.

pty

Open an async interactive PTY session backed by a WebSocket. Use as an async context manager and async iterate over :class:PtyEvent objects:: async with capsule.pty() as term: await term.write(b”echo hello\n”) async for event in term: if event.type == “output”: print(event.data.decode()) Arguments:
  • cmd str - Command to run inside the PTY. Defaults to "/bin/bash".
  • args list[str] | None - Additional arguments for cmd.
  • cols int - Initial terminal column count. Defaults to 80.
  • rows int - Initial terminal row count. Defaults to 24.
  • envs dict[str, str] | None - Additional environment variables to inject into the process.
  • cwd str | None - Working directory for the process.
Yields:
  • AsyncPtySession - An interactive async PTY session.

pty_connect

Reconnect to an existing PTY session by tag. Arguments:
  • tag str - Session tag returned in the started PTY event.
Yields:
  • AsyncPtySession - The reconnected async PTY session.

get_url

Get the proxy URL for a port exposed inside this capsule. Arguments:
  • port int - Port number to proxy.
Returns:
  • str - A wss:// (or ws://) URL that proxies to the given port inside the capsule.

create_snapshot

Create a snapshot template from this capsule’s current state. Arguments:
  • name str | None - Name for the snapshot template. Auto-generated if not provided.
  • overwrite bool - If True, overwrite an existing template with the same name. Defaults to False.
Returns:
  • Template - The created snapshot template.

wrenn.pty

PtySession Objects

Interactive PTY session backed by a WebSocket. Use as a context manager and iterate over events:: with sb.pty(cmd=“/bin/bash”) as term: term.write(b”ls -la\n”) for event in term: if event.type == “output”: sys.stdout.buffer.write(event.data) elif event.type == “exit”: break

tag

Session tag. Available after the started event.

pid

Process PID. Available after the started event.

write

Send raw bytes to the PTY stdin. Arguments:
  • data - Raw bytes to send. Base64-encoded internally.

resize

Resize the PTY terminal. Arguments:
  • cols - New column count. Must be > 0.
  • rows - New row count. Must be > 0.
Raises:
  • ValueError - If cols or rows is 0.

kill

Send SIGKILL to the PTY process.

AsyncPtySession Objects

Async interactive PTY session backed by a WebSocket. Use as an async context manager and async iterate over events:: async with sb.pty(cmd=“/bin/bash”) as term: await term.write(b”ls -la\n”) async for event in term: if event.type == “output”: sys.stdout.buffer.write(event.data) elif event.type == “exit”: break

tag

Session tag. Available after the started event.

pid

Process PID. Available after the started event.

write

Send raw bytes to the PTY stdin. Arguments:
  • data - Raw bytes to send. Base64-encoded internally.

resize

Resize the PTY terminal. Arguments:
  • cols - New column count. Must be > 0.
  • rows - New row count. Must be > 0.
Raises:
  • ValueError - If cols or rows is 0.

kill

Send SIGKILL to the PTY process.

wrenn.models._generated

Peaks Objects

Maximum values over the last 30 days.

Series Objects

Parallel arrays for chart rendering.

Encoding Objects

Output encoding. “base64” when stdout/stderr contain binary data.

Type2 Objects

Host type. Regular hosts are shared; BYOC hosts belong to a team.

wrenn.models

wrenn.capsule

Capsule Objects

A Wrenn capsule (sandbox) with e2b-compatible interface. Create directly:: capsule = Capsule(api_key=“wrn_…”) capsule = Capsule(template=“minimal”) # reads WRENN_API_KEY env Or via classmethod:: capsule = Capsule.create(template=“minimal”) Use as context manager for automatic cleanup:: with Capsule() as capsule: capsule.commands.run(“echo hello”)

__init__

Create and start a new capsule. Arguments:
  • template str | None - Template name to boot from. Defaults to the server-side default ("minimal").
  • vcpus int | None - Number of virtual CPUs. Defaults to the server-side default.
  • memory_mb int | None - Memory in MiB. Defaults to the server-side default.
  • timeout int | None - Inactivity TTL in seconds before the capsule is auto-paused. 0 disables auto-pause.
  • wait bool - If True, block until the capsule status is running before returning.
  • api_key str | None - Wrenn API key (wrn_...). Falls back to the WRENN_API_KEY environment variable.
  • base_url str | None - Wrenn API base URL. Falls back to WRENN_BASE_URL or the default production endpoint.

capsule_id

The capsule’s unique identifier. Returns:
  • str - Capsule ID assigned by the Wrenn API.

info

Cached capsule metadata from the last API call. Returns: CapsuleModel | None: The last-fetched capsule model, or None if the capsule was connected without an initial fetch.

create

Create a new capsule. Equivalent to calling Capsule(...) directly. Arguments:
  • template str | None - Template name to boot from.
  • vcpus int | None - Number of virtual CPUs.
  • memory_mb int | None - Memory in MiB.
  • timeout int | None - Inactivity TTL in seconds before auto-pause.
  • wait bool - Block until the capsule reaches running status.
  • api_key str | None - Wrenn API key. Falls back to WRENN_API_KEY env var.
  • base_url str | None - API base URL override.
Returns:
  • Capsule - A new capsule instance.

connect

Connect to an existing capsule, resuming it if paused. Arguments:
  • capsule_id str - ID of the capsule to connect to.
  • api_key str | None - Wrenn API key. Falls back to WRENN_API_KEY env var.
  • base_url str | None - API base URL override.
Returns:
  • Capsule - A capsule instance bound to the existing capsule.
Raises:
  • WrennNotFoundError - If no capsule with the given ID exists.

ping

Reset the capsule inactivity timer. Call this to prevent the capsule from being auto-paused when the inactivity TTL is set.

wait_ready

Block until the capsule status is running. Arguments:
  • timeout float - Maximum seconds to wait. Defaults to 30.
  • interval float - Polling interval in seconds. Defaults to 0.5.
Raises:
  • TimeoutError - If the capsule does not reach running state within timeout seconds.
  • RuntimeError - If the capsule enters an error, stopped, or paused state while waiting.

is_running

Check whether the capsule is currently running. Makes a live API call to fetch current status. Returns:
  • bool - True if the capsule status is running.

list

List all capsules belonging to the team. Arguments:
  • api_key str | None - Wrenn API key. Falls back to WRENN_API_KEY env var.
  • base_url str | None - API base URL override.
Returns:
  • list[CapsuleModel] - All capsules for the authenticated team.

pty

Open an interactive PTY session backed by a WebSocket. Use as a context manager and iterate over :class:PtyEvent objects:: with capsule.pty() as term: term.write(b”echo hello\n”) for event in term: if event.type == “output”: print(event.data.decode()) Arguments:
  • cmd str - Command to run inside the PTY. Defaults to "/bin/bash".
  • args list[str] | None - Additional arguments for cmd.
  • cols int - Initial terminal column count. Defaults to 80.
  • rows int - Initial terminal row count. Defaults to 24.
  • envs dict[str, str] | None - Additional environment variables to inject into the process.
  • cwd str | None - Working directory for the process.
Yields:
  • PtySession - An interactive PTY session.

pty_connect

Reconnect to an existing PTY session by tag. Arguments:
  • tag str - Session tag returned in the started PTY event.
Yields:
  • PtySession - The reconnected PTY session.

get_url

Get the proxy URL for a port exposed inside this capsule. Arguments:
  • port int - Port number to proxy.
Returns:
  • str - A wss:// (or ws://) URL that proxies to the given port inside the capsule.

create_snapshot

Create a snapshot template from this capsule’s current state. Arguments:
  • name str | None - Name for the snapshot template. Auto-generated if not provided.
  • overwrite bool - If True, overwrite an existing template with the same name. Defaults to False.
Returns:
  • Template - The created snapshot template.

wrenn._config

ConnectionConfig Objects

Resolved credentials and base URL for Wrenn API calls.

wrenn._git._auth

embed_credentials

Embed HTTP(S) credentials into a git URL. Arguments:
  • url - Git repository URL.
  • username - Username for authentication.
  • password - Password or personal access token.
Returns: URL with username:password@ embedded in the netloc. Raises:
  • ValueError - If the URL scheme is not http or https.

strip_credentials

Remove embedded credentials from a git URL. Arguments:
  • url - Git repository URL, possibly with credentials.
Returns: URL with credentials removed. Non-HTTP(S) URLs are returned unchanged.

is_auth_error

Check whether git stderr indicates an authentication failure. Arguments:
  • stderr - Combined stderr output from a git command.
Returns: True if any known auth-failure pattern is found.

build_credential_approve_cmd

Build a shell command that pipes credentials into git credential approve. Arguments:
  • username - Git username.
  • password - Password or personal access token.
  • host - Target host. Defaults to "github.com".
  • protocol - Protocol. Defaults to "https".
Returns: A shell command string safe to pass to commands.run().

wrenn._git._cmd

Pure functions that build git argument lists and parse git output. No I/O, no network, no imports from wrenn. Every build_* function returns a list[str] suitable for shlex.join(). Every parse_* function takes raw stdout and returns a typed structure.

FileStatus Objects

A single entry from git status --porcelain=v1. Attributes:
  • path str - File path relative to the repository root.
  • index_status str - Index (staged) status character.
  • work_tree_status str - Working-tree status character.
  • renamed_from str | None - Original path when status is a rename.

staged

Whether the change is staged in the index.

status

Normalized human-readable status label.

GitStatus Objects

Parsed output of git status --porcelain=v1 --branch. Attributes:
  • branch str | None - Current branch name, or None if detached.
  • upstream str | None - Upstream tracking branch.
  • ahead int - Commits ahead of upstream.
  • behind int - Commits behind upstream.
  • detached bool - Whether HEAD is detached.
  • files list[FileStatus] - Per-file status entries.

is_clean

True when there are no changed or untracked files.

has_staged

True when at least one file has staged changes.

has_untracked

True when at least one file is untracked.

has_conflicts

True when at least one file has merge conflicts.

GitBranch Objects

A single branch entry. Attributes:
  • name str - Branch name (short ref).
  • is_current bool - Whether this is the checked-out branch.

build_clone

Build git clone arguments.

build_init

Build git init arguments.

build_add

Build git add arguments.

build_commit

Build git commit arguments.

build_push

Build git push arguments.

build_pull

Build git pull arguments.

build_status

Build git status arguments for porcelain parsing.

build_branches

Build git branch arguments for structured parsing.

build_create_branch

Build git checkout -b arguments.

build_checkout

Build git checkout arguments.

build_delete_branch

Build git branch -d/-D arguments.

build_remote_add

Build git remote add arguments.

build_remote_get_url

Build git remote get-url arguments.

build_remote_set_url

Build git remote set-url arguments.

build_reset

Build git reset arguments. Arguments:
  • mode - Reset mode (soft, mixed, hard, merge, keep).
  • ref - Commit, branch, or ref to reset to.
  • paths - Paths to reset (mutually exclusive with mode).

build_restore

Build git restore arguments. Arguments:
  • paths - Paths to restore.
  • staged - Restore the index (unstage).
  • worktree - Restore working-tree files.
  • source - Commit or ref to restore from.

build_config_set

Build git config set arguments.

build_config_get

Build git config --get arguments.

build_has_upstream

Build arguments to check if current branch has upstream tracking.

parse_status

Parse git status --porcelain=v1 --branch output. Arguments:
  • stdout - Raw stdout from the git status command.
Returns: Parsed :class:GitStatus.

parse_branches

Parse git branch --format=%(refname:short)\t%(HEAD) output. Arguments:
  • stdout - Raw stdout from the git branch command.
Returns: List of :class:GitBranch.

wrenn._git.exceptions

GitError Objects

Base exception for all git operations inside a capsule. Not a subclass of :class:WrennError because git errors originate from a process exit code, not an HTTP response. Attributes:
  • message str - Human-readable error description.
  • stderr str - Raw stderr output from the git process.
  • exit_code int - Process exit code.

GitCommandError Objects

A git command exited with a non-zero exit code.

GitAuthError Objects

Authentication failed when communicating with a remote.

wrenn._git

Git operations inside a Wrenn capsule. Provides :class:Git (sync) and :class:AsyncGit (async) interfaces accessed via capsule.git. All operations execute the real git binary inside the capsule through :class:~wrenn.commands.Commands.

Git Objects

Sync git interface. Accessed via capsule.git. Executes the real git binary inside the capsule through :meth:Commands.run. Methods raise :class:GitCommandError (or :class:GitAuthError) on non-zero exit codes.

clone

Clone a remote repository into the capsule. Arguments:
  • url - Remote repository URL.
  • dest - Destination path. Defaults to the repository name derived from the URL.
  • branch - Branch or tag to check out.
  • depth - Create a shallow clone with this many commits.
  • username - Username for HTTP(S) authentication.
  • password - Password or token for HTTP(S) authentication.
  • dangerously_store_credentials - If True, leave credentials embedded in the remote URL after cloning.
  • cwd - Working directory for the command.
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds. Defaults to 300.
Returns: Command result with stdout, stderr, exit_code, and duration. Raises:
  • GitAuthError - If the remote rejected authentication.
  • GitCommandError - If clone failed for another reason.
  • ValueError - If password is provided without username.

init

Initialize a new git repository. Arguments:
  • path - Destination path for the repository.
  • bare - Create a bare repository.
  • initial_branch - Name for the initial branch (e.g. "main").
  • cwd - Working directory for the command.
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds.
Returns: Command result. Raises:
  • GitCommandError - If init failed.

add

Stage files for commit. Arguments:
  • paths - Specific files to stage. If None, stages the current directory (or all with all=True).
  • all - Stage all changes including untracked files.
  • cwd - Working directory (repository root).
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds.
Returns: Command result. Raises:
  • GitCommandError - If add failed.

commit

Create a commit. Arguments:
  • message - Commit message.
  • allow_empty - Allow creating a commit with no changes.
  • author_name - Override the commit author name.
  • author_email - Override the commit author email.
  • cwd - Working directory (repository root).
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds.
Returns: Command result. Raises:
  • GitCommandError - If commit failed.

push

Push commits to a remote. Arguments:
  • remote - Remote name. Defaults to "origin".
  • branch - Branch to push. Defaults to the current branch.
  • force - Force-push.
  • set_upstream - Set upstream tracking reference.
  • username - Username for HTTP(S) authentication.
  • password - Password or token for HTTP(S) authentication.
  • cwd - Working directory (repository root).
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds.
Returns: Command result. Raises:
  • GitAuthError - If authentication failed.
  • GitCommandError - If push failed.

pull

Pull changes from a remote. Arguments:
  • remote - Remote name. Defaults to "origin".
  • branch - Branch to pull.
  • rebase - Rebase instead of merge.
  • ff_only - Only allow fast-forward merges.
  • username - Username for HTTP(S) authentication.
  • password - Password or token for HTTP(S) authentication.
  • cwd - Working directory (repository root).
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds.
Returns: Command result. Raises:
  • GitAuthError - If authentication failed.
  • GitCommandError - If pull failed.

status

Get repository status. Arguments:
  • cwd - Working directory (repository root).
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds.
Returns: Parsed :class:GitStatus with branch info and file changes. Raises:
  • GitCommandError - If the command failed.

branches

List local branches. Arguments:
  • cwd - Working directory (repository root).
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds.
Returns: List of :class:GitBranch. Raises:
  • GitCommandError - If the command failed.

create_branch

Create and check out a new branch. Arguments:
  • name - Branch name.
  • start_point - Commit or ref to branch from.
  • cwd - Working directory (repository root).
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds.
Returns: Command result. Raises:
  • GitCommandError - If the command failed.

checkout_branch

Check out an existing branch. Arguments:
  • name - Branch name.
  • cwd - Working directory (repository root).
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds.
Returns: Command result. Raises:
  • GitCommandError - If the command failed.

delete_branch

Delete a branch. Arguments:
  • name - Branch name.
  • force - Force-delete with -D.
  • cwd - Working directory (repository root).
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds.
Returns: Command result. Raises:
  • GitCommandError - If the command failed.

remote_add

Add a remote. Arguments:
  • name - Remote name (e.g. "origin").
  • url - Remote URL.
  • fetch - Fetch after adding.
  • cwd - Working directory (repository root).
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds.
Returns: Command result. Raises:
  • GitCommandError - If the command failed.

remote_get

Get the URL of a remote. Returns None if the remote does not exist rather than raising. Arguments:
  • name - Remote name. Defaults to "origin".
  • cwd - Working directory (repository root).
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds.
Returns: Remote URL or None.

reset

Reset the current HEAD. Arguments:
  • mode - Reset mode (soft, mixed, hard, merge, keep).
  • ref - Commit, branch, or ref to reset to.
  • paths - Paths to reset.
  • cwd - Working directory (repository root).
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds.
Returns: Command result. Raises:
  • GitCommandError - If the command failed.

restore

Restore working-tree files or unstage changes. Arguments:
  • paths - Paths to restore.
  • staged - Restore the index (unstage).
  • worktree - Restore working-tree files.
  • source - Commit or ref to restore from.
  • cwd - Working directory (repository root).
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds.
Returns: Command result. Raises:
  • GitCommandError - If the command failed.

set_config

Set a git config value. Arguments:
  • key - Config key (e.g. "user.name").
  • value - Config value.
  • scope - Config scope: "local", "global", or "system".
  • cwd - Working directory (repository root). Required when scope is "local".
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds.
Returns: Command result. Raises:
  • GitCommandError - If the command failed.

get_config

Get a git config value. Returns None if the key is not set rather than raising. Arguments:
  • key - Config key (e.g. "user.name").
  • scope - Config scope: "local", "global", or "system".
  • cwd - Working directory (repository root). Required when scope is "local".
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds.
Returns: Config value or None.

configure_user

Configure git user name and email. Arguments:
  • name - Git user name.
  • email - Git user email.
  • scope - Config scope. Defaults to "global".
  • cwd - Working directory (repository root). Required when scope is "local".
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds.
Raises:
  • ValueError - If name or email is empty.
  • GitCommandError - If a config command failed.

dangerously_authenticate

Persist git credentials via the credential store. .. warning:: Credentials are written in plain text to the capsule filesystem and are accessible to any process running inside the capsule. Prefer per-operation username/password parameters on :meth:clone, :meth:push, and :meth:pull instead. Arguments:
  • username - Git username.
  • password - Password or personal access token.
  • host - Target host. Defaults to "github.com".
  • protocol - Protocol. Defaults to "https".
  • cwd - Working directory.
  • envs - Extra environment variables.
  • timeout - Command timeout in seconds.
Raises:
  • ValueError - If username or password is empty.
  • GitCommandError - If a command failed.

AsyncGit Objects

Async git interface. Accessed via capsule.git. Async mirror of :class:Git. See that class for full method documentation.

clone

Clone a remote repository into the capsule.

init

Initialize a new git repository.

add

Stage files for commit.

commit

Create a commit.

push

Push commits to a remote.

pull

Pull changes from a remote.

status

Get repository status.

branches

List local branches.

create_branch

Create and check out a new branch.

checkout_branch

Check out an existing branch.

delete_branch

Delete a branch.

remote_add

Add a remote.

remote_get

Get the URL of a remote. Returns None if not found.

reset

Reset the current HEAD.

restore

Restore working-tree files or unstage changes.

set_config

Set a git config value.

get_config

Get a git config value. Returns None if not set.

configure_user

Configure git user name and email.

dangerously_authenticate

Persist git credentials via the credential store. .. warning:: Credentials are written in plain text to the capsule filesystem. Prefer per-operation username/password parameters instead.