open-swe/agent/integrations/local.py
Johannes du Plessis ce24a47cdf
fix: auto-create local sandbox root dir (#1402)
create_local_sandbox now mkdir -p's the resolved root dir, so a custom
LOCAL_SANDBOX_ROOT_DIR (or a /tmp path cleared on reboot) no longer fails
sandbox work-dir resolution.
2026-06-03 23:47:08 +00:00

28 lines
904 B
Python

import os
from deepagents.backends import LocalShellBackend
def create_local_sandbox(sandbox_id: str | None = None):
"""Create a local shell sandbox with no isolation.
WARNING: This runs commands directly on the host machine with no sandboxing.
Only use for local development with human-in-the-loop enabled.
The root directory defaults to the current working directory and can be
overridden via the LOCAL_SANDBOX_ROOT_DIR environment variable. It is
created if it does not already exist.
Args:
sandbox_id: Ignored for local sandboxes; accepted for interface compatibility.
Returns:
LocalShellBackend instance implementing SandboxBackendProtocol.
"""
root_dir = os.getenv("LOCAL_SANDBOX_ROOT_DIR", os.getcwd())
os.makedirs(root_dir, exist_ok=True)
return LocalShellBackend(
root_dir=root_dir,
inherit_env=True,
)