> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mirage.strukto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Policy

> Decide what an agent may run, read, write and connect to in the virtual terminal.

Policy decides what an agent may do in the virtual terminal: the commands
it runs, the files it reads and writes, and the connections it opens. A
policy is a class with a pair of methods for each thing an agent does, or
[programs](https://docs.mirage.strukto.ai/home/policy/scripts.md) a profile names for those methods:

| The agent | Methods |
| - | - |
| runs a line | `pre_execute`, `post_execute` |
| runs a command or CLI | `pre_command`, `post_command` |
| uses files: commands, file CLIs, runtime file APIs, file tools, `session.vfs`, FUSE, SFTP | `pre_vfs`, `post_vfs`; see [Lifecycle](https://docs.mirage.strukto.ai/home/policy/policies.md#lifecycle) |
| opens a connection: `curl`, a CLI's API call, a mount's read, an SDK | `pre_network`, `post_network` |

A `pre_` method runs before the action executes; a `post_` method runs afterward
with the execution result. A policy decision can permit, refuse, [request host approval](https://docs.mirage.strukto.ai/home/policy/policies.md#asks),
bound the output, or select the target machine. No policy can permit what
another refuses.

Policies evaluate in sequence: built-in checks first (mount modes, path restrictions,
[machine routing](https://docs.mirage.strukto.ai/home/policy/route-machine.md)), followed by the session profile, and finally
the workspace policies in the order they were added.

## Why not a tool-call check

A harness's tool-call check, such as Claude Code's `PreToolUse` or an SDK's
`can_use_tool`, sees one tool call: a tool name and a string such as
`cat $(ls /data | head -1)`. A Mirage policy runs inside the shell and the
filesystem, so it sees what that string only implies.

| | Tool-call check | Mirage policy |
| - | - | - |
| Commands | the raw string; `$( )`, `xargs`, `find -exec`, `eval` and variables hide what runs | every command after expansion, nested ones included |
| Files | the paths written in the string | profile rules and file hooks check paths a command reaches, such as each one `grep -r`, `tar` or `cp -r` reaches |
| Ways in | that harness's own tools | every session and entry point: the SDK, MCP, HTTP, RPC, SSH, FUSE |

## In this section

* [Policies](https://docs.mirage.strukto.ai/home/policy/policies.md): write one: its methods, what each can
  answer, and asks.
* [Scripts](https://docs.mirage.strukto.ai/home/policy/scripts.md): write one as a program that runs
  sandboxed on monty or Python on wasm, with the same context as JSON.
* [Explain](https://docs.mirage.strukto.ai/home/policy/explain.md): what the agent sees of policy, and how
  it asks what a line would do before running it.
* [Route Machine](https://docs.mirage.strukto.ai/home/policy/route-machine.md): choose the machine for a
  line, from a script.
* [Route Network](https://docs.mirage.strukto.ai/home/policy/route-network.md): send a connection to one
  address to another, per workspace and per session.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.