Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ AGENT_ENV_ENVIRONMENT=dev
# AGENT_ENV_IMAGE_STORE=local

# Where local sandboxes keep their work folders (default ~/.agent-env-sandboxes; on macOS, a path Docker Desktop
# shares). A sandbox's folder is made before anything it runs, so a supervisor that gives a run a folder of its own
# can clean up after killing it: terminate each id local_sandbox_ids() lists, then remove its folder.
# shares). A sandbox's folder is made before anything it runs, so a supervisor that gives a run a folder of its own,
# and starts it in a new session so that killing the run's process group spares the supervisor, can clean up after
# that kill: terminate each id local_sandbox_ids() lists, then remove its folder.
# A terminate that raises means the sandbox isn't fully gone: keep its folder and retry.
# AGENT_ENV_LOCAL_SANDBOX_DIR=~/.agent-env-sandboxes

# Secret store backend (what secret: references in config resolve through):
Expand Down
7 changes: 5 additions & 2 deletions src/agent_env/bundle/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,11 @@ def run_bundle(
Each run's sandboxes are torn down as it ends, so the contexts returned record sandboxes that are gone.
``keep`` leaves them up instead, for the caller to use and then remove with ``BundleRun.teardown()``.
Ctrl-C or SIGTERM cancels the runs and tears down every one, kept or not, then raises ``RunInterrupted``
with the result. A process killed outright tears down nothing: a supervisor that may have to kill it gives it an
``AGENT_ENV_LOCAL_SANDBOX_DIR`` of its own, then terminates what ``local_sandbox_ids`` finds there.
with the result. A process killed outright tears down nothing: a supervisor that may have to kill it starts it
with an ``AGENT_ENV_LOCAL_SANDBOX_DIR`` of its own in a new session (``start_new_session=True``), so killing the
run's whole process group spares the supervisor; on macOS that kill is all that stops the commands the run started
on this machine. It then terminates each sandbox ``local_sandbox_ids`` finds there, keeping one whose termination
raises, which isn't fully gone, to retry.

It runs its own event loop, and turns namespace routing on for the whole process while it runs, so it
suits the CLI and scripts, not a service. From async code, call it in a thread; there it can't take over
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,9 @@ def _copy_into_container(source: Path, container: str, destination: str) -> None


def local_sandbox_ids() -> list[str]:
"""The ids of the local sandboxes with a work folder under the sandbox root. A folder is made before anything its
sandbox runs, so a supervisor that gave a run its own ``AGENT_ENV_LOCAL_SANDBOX_DIR`` cleans up after killing it by
terminating each id here (``LocalSandboxProvider().terminate_sandbox``) and removing its folder."""
"""The ids of the local sandboxes with a work folder under the sandbox root, made before anything its sandbox runs:
a supervisor that gave a run its own ``AGENT_ENV_LOCAL_SANDBOX_DIR`` terminates each after killing it, removing its
folder, and keeps one whose ``LocalSandboxProvider().terminate_sandbox`` raises, not fully gone, to retry."""
root = _local_sandbox_root_path()
if not root.is_dir():
return []
Expand Down
Loading