> ## 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.

# Workspace

> Refuse a workspace before a server builds it, with pre_workspace.

TypeScript spells the method in camelCase (`preWorkspace`).

| Method | Runs | Can return |
| - | - | - |
| `pre_workspace` | on a server, before a create, clone or load builds anything | Deny |

## How it applies

Only a server asks `pre_workspace`, with the policies it was started with
(see [Server policies](https://docs.mirage.strukto.ai/home/access/http.md#server-policies)). It sees the
config before any mount is built or any secret is read: a create's whole
config, a clone's or a load's `override`. `ctx` carries `config` and
`caller` only.

## Example

```python Python theme={null}
from mirage.policy import Deny, Policy, WorkspaceContext

class NoHostFiles(Policy):
    async def pre_workspace(self, ctx: WorkspaceContext) -> Deny | None:
        mounts = ctx.config.get("mounts") or {}
        if any(block.get("vfs") == "disk" for block in mounts.values()):
            return Deny("disk mounts are not offered here")
        if "machines" in ctx.config:
            return Deny("machines are set by the operator")
        return None
```

```typescript TypeScript theme={null}
const noHostFiles: Policy = {
  preWorkspace(ctx) {
    const mounts = (ctx.config.mounts ?? {}) as Record<string, { vfs?: string }>
    if (Object.values(mounts).some((block) => block.vfs === 'disk')) {
      return { kind: 'deny', reason: 'disk mounts are not offered here' }
    }
    if ('machines' in ctx.config) {
      return { kind: 'deny', reason: 'machines are set by the operator' }
    }
    return null
  },
}
```

The create answers 403 with the reason, and nothing is built.


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