Skip to main content
Call these when your agent runs in the same process as the workspace. Every other way in ends in the same calls.

Workspace

One terminal over the backends mounted at each prefix.
dict[str, VFS]
required
The backend at each prefix, such as {"/": RAMVFS(), "/s3": S3VFS(config)}.
MountMode
default:"MountMode.READ"
The mode a mount gets when it sets none: READ, WRITE or EXEC.
dict[str, SessionProfile]
Named profiles a session can be created under.
str
The profile a session gets when it names none.
list[Policy]
Policies every line passes through.
AskHandler
Answers an ask while the line waits. Without one, asks wait in ws.decisions.
The other parameters (cache, index, store, runtimes, clis, env, secrets, command_limits, …) are the top-level YAML keys.

ws.session

The Session every call below runs as. It creates the session when the id is new and adopts it when it exists. profile and mounts apply only on create, and raise ValueError for an existing session. ws.create_session is the same call without the handle.

ws.list_sessions, ws.close_session

List the sessions, or close one: its lines are cancelled and its jobs end. The default session cannot be closed.

ws.cancel, ws.kill

Stop a session’s work, or every session’s with no id, and leave the sessions open. cancel cancels the running and queued lines, whichever way they came in, and returns once they have ended; each ends with MirageAbortError. kill kills the background jobs (cmd &) and the processes runtimes started. Each answers how many it stopped.

ws.snapshot, Workspace.load

Save the workspace to a tar and rebuild it from one. target and source are a path or a file object, or an object key with s3=. snapshot answers the tar’s size in bytes. While it captures, new lines and file writes wait, and running ones get 30 seconds to end, else it raises OSError (EBUSY); disk mount files are streamed, never held whole. See Snapshots for what a tar holds.

ws.copy

A deep copy, without a tar in between. RAM and disk mounts are copied, so a write in the copy never reaches the original; a disk mount’s copy lives in a new temporary directory. Sessions, history and profiles come along. Remote backends such as S3 or Redis are shared, so a write through the copy reaches the same bucket. Policies are not copied.

ws.decisions

The asks waiting for a host. Each one belongs to the session that ran the line: pending() lists every session’s, pending("agent") one session’s, and an answer never reaches another session. outcome is Outcome.ALLOW or Outcome.DENY. Scope.ONCE answers the one line, so its retry runs or is refused; Scope.SESSION allows every line the rule covers for the rest of that session.

ws.close

Stops its jobs and closes its mounts. Sessions and history stay in the workspace’s store.

Session

One session’s handle, from ws.session. Every call on it answers under the session’s profile, working directory and environment. ws.shell, ws.glob, ws.vfs and ws.tools are the same calls as the workspace’s default session.
str
SessionState
The session’s record, as ws.list_sessions answers it.
Ops
The file API, below.
MirageToolOperations
The agent tools, below.
Decisions
The workspace’s asks ledger, which this session’s questions land in.

session.shell

Runs a shell line as the session. A non-zero exit is a result, not an exception.
bytes | AsyncIterator[bytes]
The line’s stdin. An async iterator streams it.
str
A working directory for this line only. A cd in the line does not leak.
dict[str, str]
Variables for this line only.
asyncio.Event
Setting it stops the line and raises MirageAbortError.
bool
default:"True"
False keeps the line out of history.

session.glob

The paths a pattern matches, as the session sees them.

session.explain

What session.shell or a session.vfs call would do, without running it: a line’s verdict and parse tree, a VFS call’s verdict and error, each with every policy’s answer. See Explain.

session.vfs

The file API, run as the session. Paths are absolute, bytes are bytes. A missing path raises FileNotFoundError and a refused one PermissionError.

session.tools

The seven agent tools, for a model rather than a program: every answer is text, and a failure is is_error, never an exception. call takes a tool’s name and its JSON input, the form an agent loop gets from the model. The session has one table, shared by every caller, so write and edit refuse a file the agent has not read in full, or one that changed since it read it. names() is the tools the session’s profile leaves it, which MCP, RPC and the agent adapters offer: shell needs a command the allow list installs, ls and grep those commands, write and edit a mount the session may write. mirage.workspace.tools.tool_descriptions has each tool’s description and JSON schema to hand the model, and the agent adapters wire the tools into each framework. MirageToolOperations(session, stale_write_protection=False), from mirage.workspace.tools.tool_operations, is a table without the read guard.