# Sandboxing

If *aitm* founds the [bwrap](https://github.com/containers/bubblewrap "https://github.com/containers/bubblewrap") executable on the path, it will use it to sandbox the [cli/harness](harness "harness").

## Permissions

The permissions are:

* read all

* write the current directory

* write the runtime directories (known directories where the agent writes) such as:

  <!-- -->

  * the configuration/agent directory
  * the session directory

* write the paths defined in the [AITM_SANDBOX_WRITABLE_PATHS](#extra-writable-path "#extra-writable-path")

## Debug

### How to see if my harness is wrapped?

If the agent is sandboxed, we inject in the env the *AITM_SANDBOX_PROVIDER* env. You can see it with the [aitm-status command](status "status") of each agent.

You can also check that you agent is wrapped with the following command:

Example with bwrap:

```bash
pstree -ap $(pgrep -d, aitm)
```

```markdown
aitm,261614 /home/admin/.virtualenvs/aitm/bin/aitm pi
├─bwrap,261620 --ro-bind / / --dev /dev --proc /proc --tmpfs /tmp --bind /home/user/code/project /home/user/code/project
--chdir /home/user/code/project --die-with-parent --unshare-pid ...
│ └─bwrap,261621 --ro-bind / / --dev /dev --proc /proc --tmpfs /tmp --bind /home/user/code/project
/home/user/code/project --chdir /home/user/code/project --die-with-parent ...
│ └─pi,261622
│ ├─{pi},261623
│ ├─{pi},261624
│ └─{pi},261632
├─{aitm},261618
└─{aitm},261619
```

## Config

### Mount an Emtpy Temporary Directory

By default, we bind the host temporary directory (ie */tmp/* is seen by the agent/cli)

If you don't want, you can mount a temporary empty tmp (*tmpfs*) and specify the mount point with:

* the *AITM_SANDBOX_TMPFS_TARGET* [environment variable](env "env")
* or the cli option *-sbtt* or *--sandbox-tmpfs-target*

Example:

```bash
export AITM_SANDBOX_TMPFS_TARGET="/tmp" aitm
aitm -sbtt "/tmp"
aitm --sandbox-tmpfs-target "/tmp"
```

### Extra Writable Path

You can define extra writable path separated by a colon *:* via:

* the *AITM_SANDBOX_WRITABLE_PATHS* [environment variable](env "env")
* or the cli option *--sbp*/ *--sandbox-writable-paths*

Example:

```bash
export AITM_SANDBOX_WRITABLE_PATHS="/home/user/tmp1:/home/user/tmp2:" aitm
aitm --sandbox-writable-paths "/home/user/tmp1:/home/user/tmp2:"
aitm --sbp "/home/user/tmp1:/home/user/tmp2:"
```

### Disable

You can disable sandboxing via:

* the *AITM_SANDBOX_DISABLE* [environment variable](env "env")
* or the cli option *--sbd*/ *--sandbox-disable*

Example:

```bash
export AITM_SANDBOXING_DISABLE="1"
aitm --sandbox-disable 
aitm --sbd
```
