# Give an agent a sandbox

Run work you don't trust, such as code an AI agent downloaded, in a clone that's deleted when it stops.

Requires [OSMates Pro](https://osmates.com/docs/editions#what-pro-adds).

## Make a sandbox

Sandboxes are made in Terminal or by an AI agent. Clone a machine with the `agent-sandbox` preset, then start it:

```sh
osmates vm clone dev scratch --preset agent-sandbox
osmates vm start scratch
```

To start from the [template for agents](https://osmates.com/docs/templates#the-template-for-agents), a small Debian machine without a desktop, leave out the source: `osmates vm clone scratch --preset agent-sandbox`.

An AI agent makes one with `vm_clone` and `preset` set to `agent-sandbox`. To run a coding agent in a machine, use [`osmates code`](https://osmates.com/docs/code). For an MCP server, see [Run an MCP server in a sandbox](https://osmates.com/docs/mcp-sandbox).

## Sandbox settings

A sandbox differs from an ordinary clone:

- It's deleted when it stops.
- It has no shared folders and no shared clipboard.
- Its network access is never Open.
- It records AI agent sessions.
- Windows and macOS sandboxes are muted, and keep the screen on and unlocked while idle.

Nobody, including you, can later share a folder or the clipboard with it, or set its network access to Open. An AI agent can only narrow that access.

## Network access

A sandbox's access depends on its source machine:

- A source with Open access gives Allowed Destinations Only, with the package registry, GitHub, and model API presets.
- A source with Allowed Destinations Only or Blocked keeps that mode and its rules. `host` rules and ranges that reach a private or local address are dropped, and `vm clone` lists them.

The filter is on from the first packet, and other machines on a shared network need a rule too. Windows can report no internet connection, but allowed destinations work.

To add a rule back, replace `<rule>` with it:

```sh
osmates vm egress scratch --allow <rule>
```

For modes and rules, see [Limit what a machine reaches](https://osmates.com/docs/egress).

## If the screen still sleeps or locks

The guest's sleep, screen saver, and screen lock are turned off when its guest agent connects. [Linux desktops](https://osmates.com/docs/linux-desktop#turn-the-lock-screen-back-on) in the library never lock or blank. To see whether the guest took the settings:

```sh
osmates vm events scratch
```

A setting that didn't take is tried again at the next connection.

If the source had a machine inactivity limit, Windows applies the change after a restart. To restart it from inside the guest, which keeps the sandbox running:

```sh
osmates vm exec scratch -- shutdown.exe /r /t 0
```

If a Group Policy sets the screen saver or a display or sleep timeout, OSMates leaves it. The event names the policy. Change it in the source machine.
