ReMe/reme/utils/file_sandbox/__init__.py
xyf2020 2767836b21
feat(sandbox): Add Home AutoBash plugin and path-scoped execution sandboxes (#603)
* Add sandboxed Python execution and home AutoBash plugin

* Harden read-only shell commands and filesystem sandboxes

* Group file sandbox backends in one package

* Fix macOS file sandbox isolation and runtime access

* Refine file sandbox limits and executor checks

* Harden AutoBash policy and macOS sandbox supervision

* fix(home): require ReMe release with file sandbox

* refactor(home): simplify sandbox calls and redundant tests

* fix(execution): bound output and clean up cancelled sandbox startup

* fix(tests): mock Seatbelt platform requirements on Linux

* fix(home): block Git help helpers and harden sandbox cleanup

* Fix sandbox runtime links and subprocess cleanup

* ci: cover Home plugin tests

* test: wait for pipeline descendants to exit after cancellation

* fix: align Home dependencies and preserve cleanup cancellation

Require ReMe 0.4.2.1 and verify isolated Home wheel installation in package CI. Share cancellation-safe cleanup with thread calls, retain AnyIO cancellation semantics, and record Bubblewrap mount targets during argument construction.
2026-10-27 18:08:26 +08:00

18 lines
849 B
Python

"""Select a local file sandbox for supported operating systems."""
import sys
from .file_sandbox_backend import FileSandboxBackend
from .path_bubble_backend import PathBubbleBackend
from .path_seatbelt_backend import PathSeatbeltBackend
def create_file_sandbox_backend(*, memory_limit_mib: int | None = None, **kwargs) -> FileSandboxBackend:
"""Construct the platform backend; never silently execute without isolation."""
if sys.platform.startswith("linux"):
limit = 4096 if memory_limit_mib is None else memory_limit_mib
return PathBubbleBackend(memory_limit_mib=limit, **kwargs)
if sys.platform == "darwin":
limit = 0 if memory_limit_mib is None else memory_limit_mib
return PathSeatbeltBackend(memory_limit_mib=limit, **kwargs)
raise RuntimeError(f"No file sandbox backend for {sys.platform}")