> For the complete documentation index, see [llms.txt](https://docs.zenml.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zenml.io/stacks/stack-components/sandboxes/local.md).

# Local

The local sandbox flavor runs commands as `subprocess.Popen` on the same machine as the step, with the same OS user, full filesystem access, and full network access. **It provides no isolation.**

It is intended for:

* Quickstart / examples that should work without a Modal or other cloud account.
* Unit tests of code that consumes the `BaseSandbox` interface.
* Local development against the abstraction.

It is **not** intended for running untrusted LLM-generated code. For real isolation, use a different sandbox flavor.

## How to register

```bash
zenml sandbox register local-sb --flavor=local
zenml stack update --sandbox local-sb
```

## Settings

The Local sandbox inherits `BaseSandboxSettings` and adds `forward_env`.

* `sandbox_environment`: explicit environment variables to set inside the subprocess.
* `forward_env`: which parent-process variables are forwarded into the session. Set `forward_env=True` to forward the entire parent environment, `False` to forward nothing, or pass a list of names to forward exactly those. It defaults to a set that keeps command resolution and UTF-8 stdio working: `PATH`, `HOME`, `LANG`, `LC_ALL`, `TMPDIR`, `TERM`.

Secrets in the parent environment stay isolated from the session unless `forward_env` is `True` or names them explicitly. `sandbox_environment` is layered on top and overrides forwarded variables on a key collision.

## What it doesn't support

| Feature                         | Local | Notes                                                                                                                                                  |
| ------------------------------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `snapshot()` / `restore()`      | ❌     | No state-capture primitive locally.                                                                                                                    |
| `attach(session_id)`            | ❌     | Sessions are bound to the parent process; not re-attachable.                                                                                           |
| `upload_file` / `download_file` | ❌     | Files live in the session workdir already; use plain Python file I/O.                                                                                  |
| Streaming output                | ✅     | `subprocess.PIPE` line-buffered.                                                                                                                       |
| Sandbox log forwarding          | ✅     | Each `exec` emits a `$ <command>` marker plus stdout/stderr lines + an `OK`/`FAIL exit code <code>` trailer into the step's `sandbox:<id>` log source. |
| `destroy()`                     | ✅     | Delegates to `close()`; removes the session workdir.                                                                                                   |

## When to use it

Use the local flavor when:

* You want to try the Sandbox abstraction without setting up infrastructure.
* You're running an example that demonstrates the agent / sandbox split but doesn't care about isolation.
* You're writing a unit test that exercises a tool that consumes a `SandboxSession`.

Otherwise, use a containerized flavor.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.zenml.io/stacks/stack-components/sandboxes/local.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
