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.
Record<string, VFS>
required
The backend at each prefix, such as { '/': new RAMVFS(), '/s3': new S3VFS(config) }.
MountMode
default:"MountMode.READ"
The mode a mount gets when it sets none: READ, WRITE or EXEC.
Record<string, SessionProfile>
Named profiles a session can be created under.
string
The profile a session gets when it names none.
Policy[]
Policies every line passes through.
AskHandler
Answers an ask while the line waits. Without one, asks wait in ws.decisions.
The other options (cache, index, store, runtimes, clis, env, secrets, commandLimits, …) are the top-level YAML keys, in camelCase.

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 throw for an existing session. ws.createSession is the same call without the handle.

ws.listSessions, ws.closeSession

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 resolves once they have ended; each rejects with an AbortError. 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. With no target, snapshot answers the tar’s bytes; with one, its size. target and source are a path, or an object key with s3; source can also be the bytes. While it captures, new lines and file writes wait, and running ones get 30 seconds to end, else it rejects with an EBUSY error; a path target streams disk mount files rather than holding them 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, the default, 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.
string
SessionState
The session’s record, as ws.listSessions 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.
Uint8Array | AsyncIterable<Uint8Array>
The line’s stdin. An async iterable streams it.
string
A working directory for this line only. A cd in the line does not leak.
Record<string, string>
Variables for this line only.
AbortSignal
Aborting it stops the line, which throws an AbortError.
boolean
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. In a browser (no async task isolation) explain.vfs throws and explain.shell’s policies act for real. See Explain.

session.vfs

The file API, run as the session. Paths are absolute, bytes are Uint8Array. A failure throws an Error whose code is the POSIX name, as Node’s fs does: ENOENT, EACCES, EROFS.

session.tools

The seven agent tools, for a model rather than a program: every answer is text, and a failure is isError, never a throw. 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. readMedia(path) answers an image or a PDF as media instead of numbered text, for adapters that hand media to the model. @struktoai/mirage-core/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. new MirageToolOperations(session, false), from @struktoai/mirage-core/workspace/tools/tool_operations, is a table without the read guard.