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

# Agent Code Isolation

> How Genesis keeps code that agents run inside the folders its person and agent may use, what a blocked folder looks like, how to share one, and how to turn enforcement off.

Agents write and run Python with `execute_python_code`. Genesis runs that code in a
sandbox. The sandbox keeps the code away from the server, its credentials and its
storage. With **run grants** enforced, it also limits the code to the folders that the
person and the agent who started the run may use. Genesis already uses those access rules
for repositories, GenesisApps and conversations. Run grants apply the same rules to the
code an agent runs.

## What changed

* **Code runs in a kernel sandbox on every deployment that supports it.** On root
  installs (Docker, Kubernetes, ECS, SPCS) the code first drops to the separate
  `cortex_sandbox` user. Then Linux namespaces, Landlock and seccomp confine it. Before,
  only Databricks Apps confined it this way.
* **Each install tests its own sandbox at startup.** The test picks the strongest level
  that works on the host. Administrators see the result on the **Code Isolation** card.
  If a level stops working, the install falls back one level and records why.
* **Each run knows which folders its person and agent may use.** This is controlled by
  the `security.run_grants` setting.
  * `shadow` is the default. Runs work out their grants and log the folders they would
    refuse, without blocking anything.
  * `enforce` blocks those folders.
* **A blocked folder is locked, not hidden.** It stays in directory listings, and opening
  it fails with "permission denied", not "not found". The agent is told which folder was
  blocked, why, and who can open it.

## Isolation levels

| Level | On the card | What the code gets |
| - | - | - |
| `full` | Full isolation | User, mount and pid namespaces, Landlock and seccomp. The code sees only the folders it is granted. Folders it is refused stay locked, and processes outside the run cannot be signalled. |
| `landlock_only` | Landlock only | Landlock and seccomp. File grants are still enforced. Folder names outside the run's grants stay visible, and processes outside the run can still be signalled. |
| `none` | No kernel isolation | The host's kernel has no Landlock. With `security.code_isolation` set to `confine`, runs are refused. With `off`, the code runs without kernel confinement: on a root install as `cortex_sandbox`, otherwise as the server's own user. |

Docker's default seccomp profile, and ECS on Fargate, give **Landlock only**. On Docker
and on ECS with EC2 instances, Genesis ships a profile that gives **Full isolation**. See
[Code isolation](https://docs.genesiscomputing.com/docs/deployments/Docker/Genesis-Container-Distribution.md#code-isolation)
in the Docker guide. When it applies, the card names the missing profile.

## What a block looks like

With `security.run_grants` set to `enforce`, code that opens a folder outside its grants
gets a permission error from the operating system. The run's result then lists each
blocked folder with a sentence for the agent to pass on, for example:

> Access to `repos/finance-models` was denied (no view grant on the repository). Ask the
> owner, Dana Lee, to share it with this agent.

The end of the sentence depends on who can open the folder:

* **The person can grant it themselves:** "You can grant it: share it with this agent."
* **Someone else owns it:** "Ask the owner, *owner*, to share it with this agent."
* **No owner is recorded:** "Ask an administrator to share it with this agent."
* **Sharing would not help:** the sentence says what would. For example, "continue in a
  conversation that is not private to use it", or "ask an administrator to let you use
  this agent". Genesis's own storage, secrets and the private person store are never
  shared with an agent run.

The run is not started at all in two cases:

* Its grants could not be worked out.
* Its scratch folder sits inside a folder it is refused.

In `shadow` mode the same sentences say the folder *would be* denied once run grants are
enforced, and the run continues.

A Python step in a [Flow](https://docs.genesiscomputing.com/docs/User-Guide/Flows.md) reports blocked folders in its step
summary, or in its error when the step fails.

## How to share a folder

A run may read what its person may read, in the agent they are using:

* **A repository:** the repository's owner or an administrator opens it in **Git**,
  chooses **Manage Access**, and grants the person, or one of their roles, **View** or
  **View and edit**. A **Shared** repository is readable by everyone who can open Git
  repositories.
* **A GenesisApp or a conversation:** the run may read it when the person may read it.
* **Another agent's repository:** the person needs to be able to use that agent. One of
  the agent's managers, or an administrator, adds them under **Users** on the agent's
  **Sharing** tab.

The next run picks up the change; nothing needs to restart.

## The Code Isolation card and the support bundle

Administrators find the read-only **Code Isolation** card on
[Workspace Policies](https://docs.genesiscomputing.com/docs/Setup/Workspace-Policies.md#code-isolation). It shows:

* the level and why;
* whether agent code actually runs at that level on this install;
* any step of the startup test that failed;
* level changes since the server started;
* parts of the sandbox that keep failing runs;
* the folders runs were most often refused, or would be refused in `shadow` mode, with the
  rule and the number of runs.

The card describes the current server process and starts over at each restart.

A [support bundle](https://docs.genesiscomputing.com/docs/Setup/Support-And-Enhancements.md) carries the same report as
`isolation.json`. Folder names are left out: the bundle gives only how many blocked
folders there were. Launcher error text, which can name a folder, is replaced with a fixed
sentence. Only the admin card shows the folders.

## Turning enforcement off

These settings are deployment overrides. Set them as environment variables for the
Genesis server (Docker `--env-file` or `config.env`, a Helm chart's `config.extraEnv`, or
the app's environment), then restart. A value set this way cannot be changed from the UI.

| Override | Values | What it does |
| - | - | - |
| `GENESIS__SECURITY__RUN_GRANTS` | `shadow` (default), `enforce`, `off` | `shadow` logs what enforcement would block and blocks nothing. `enforce` blocks folders outside the run's grants. `off` works out no grants. An unknown value is read as `enforce`. |
| `GENESIS__SECURITY__CODE_ISOLATION` | `off` (default), `confine` | Applies to servers that are not root, such as a Databricks App. `confine` runs agent code under Landlock and seccomp, and refuses to run it on a kernel without Landlock. `off` runs it as the server's own user. Root installs always drop to `cortex_sandbox` and confine wherever the kernel has Landlock, whatever this says. |

**Container profiles (Docker and ECS with EC2 instances).** The image ships
`genesis-seccomp.json` and, for hosts that run AppArmor, `genesis-sandbox.apparmor` in
`/app/config/security/`. They let the namespace layer start, giving **Full isolation**
instead of **Landlock only**. The `genesis_server` launcher and `docker-compose.yml` use
the seccomp profile. Starting without them is the way back to Docker's defaults. See
[Code isolation](https://docs.genesiscomputing.com/docs/deployments/Docker/Genesis-Container-Distribution.md#code-isolation).

To stop blocking folders while keeping the sandbox, set
`GENESIS__SECURITY__RUN_GRANTS=shadow`. The card and the logs still show which folders
runs reach that enforcement would block. The full descriptions are in the
[Configuration Reference](https://docs.genesiscomputing.com/docs/Setup/Configuration-Reference.md).

## In a later release

These parts of agent isolation are not in this release:

* **A private work folder for each person and agent.** A run writes new work there.
* **Sharing one agent's workspace with another agent.** People who may use both agents
  can then read it in the second agent's runs.
* **Ask the owner.** A person whose run was refused a folder asks its owner, who grants
  view in one click.
* **A preview on the Code Isolation card** of the folders a person and agent's next run
  would get.
* **GenesisApps confined on root servers,** with a setting to turn that off
  (`apps.confine_on_root_servers`).
* **Confined local Talend jobs,** with a setting that lists the folders a job may write
  outside its grants (`talend.writable_roots`).
