# NousResearch/hermes-agent · Terminal sandbox persistence across conversation turns

## Open now

- Nothing open on GitHub.

These issues and PRs concern persistent terminal sandboxes (docker/daytona/modal) being torn down between turns despite configuration indicating they should survive. A fix is proposed to make sandbox environments persist across turns as intended.

## TL;DR

- 3 member(s): 0 open issue(s), 1 closed issue(s), 0 open PR(s), 1 merged PR(s), 1 PR(s) closed without merging.
- A fix was merged to main in PR #6412. Verify it addresses your case.
- **Recommended:** read PR #6412 (and any competing PRs below) before filing. Confirm the merged change covers your symptom.

## Maintainer resolution verdict

- Internal-tracker verdict over this cluster's issue members: `resolved` · deciding PR(s): `pr-6412`. This is distinct from the fix status above. Weigh it yourself.

## How this cluster was grouped

- Link evidence (`STRUCTURAL_SPANNING`): every member is connected by structural evidence: shared changed files, or a closing/superseded reference.
- Pairwise link density `0.67`: the share of member pairs that carry a link, counting a structural link in full and a relevance-only link at 0.36. `1.00` means every pair is linked.

## Closed / duplicate issues

- #6369: Persistent terminal sandboxes (docker/daytona/modal) are torn down every turn, contradicting \`terminal.lifetime_seconds\`

## Prior & competing PRs

- **#6412: fix(terminal): persistent sandbox envs survive between turns**. merged to main · fix tier `verified`
  - maintainer direction: category `merged`
  - files: `run_agent.py`, `tools/terminal_tool.py`
  - fix hunks:
  - `run_agent.py`

    ```diff
    @@ -66,7 +66,7 @@
         handle_function_call,
         check_toolset_requirements,
     )
    -from tools.terminal_tool import cleanup_vm, get_active_env
    +from tools.terminal_tool import cleanup_vm, get_active_env, is_persistent_env
     from tools.tool_result_storage import maybe_persist_tool_result, enforce_turn_budget
     from tools.interrupt import set_interrupt as _set_interrupt
     from tools.browser_tool import cleanup_browser
    ```

    ```diff
    @@ -1687,9 +1687,25 @@ def _extract_reasoning(self, assistant_message) -> Optional[str]:
             return None
     
         def _cleanup_task_resources(self, task_id: str) -> None:
    -        """Clean up VM and browser resources for a given task."""
    +        """Clean up VM and browser resources for a given task.
    +
    +        Skips ``cleanup_vm`` when the active terminal environment is marked
    +        persistent (``persistent_filesystem=True``) so that long-lived sandbox
    +        containers survive between turns. The idle reaper in
    +        ``terminal_tool._cleanup_inactive_envs`` still tears them down once
    +        ``terminal.lifetime_seconds`` is exceeded. Non-persistent backends are
    +        torn down per-turn as before to prevent resource leakage (the original
    +        intent of this hook for the Morph backend, see commit fbd3a2fd).
    +        """
             try:
    -            cleanup_vm(task_id)
    +            if is_persistent_env(task_id):
    +                if self.verbose_logging:
    +                    logging.debug(
    +                        f"Skipping per-turn cleanup_vm for persistent env {task_id}; "
    +                        f"idle reaper will handle it."
    +                    )
    +            else:
    +                cleanup_vm(task_id)
             except Exception as e:
                 if self.verbose_logging:
                     logging.warning(f"Failed to cleanup VM for task {task_id}: {e}")
    ```
  - `tools/terminal_tool.py`

    ```diff
    @@ -814,6 +814,23 @@ def get_active_env(task_id: str):
             return _active_environments.get(task_id)
     
     
    +def is_persistent_env(task_id: str) -> bool:
    +    """Return True if the active environment for task_id is configured for
    +    cross-turn persistence (``persistent_filesystem=True``).
    +
    +    Used by the agent loop to skip per-turn teardown for backends whose whole
    +    point is to survive between turns (docker with ``container_persistent``,
    +    daytona, modal, etc.). Non-persistent backends (e.g. Morph) still get torn
    +    down at end-of-turn to prevent leakage. The idle reaper
    +    (``_cleanup_inactive_envs``) handles persistent envs once they exceed
    +    ``terminal.lifetime_seconds``.
    +    """
    +    env = get_active_env(task_id)
    +    if env is None:
    +        return False
    +    return bool(getattr(env, "_persistent", False))
    +
    +
     def get_active_environments_info() -> Dict[str, Any]:
         """Get information about currently active environments."""
         info = {
    ```
- **#6370: fix(terminal): persistent sandbox envs survive between turns**. closed without merge
  - maintainer direction: category `merged_via`; implication `superseded`; refs `#6412`

## Fix status

- Merged to main in PR #6412 (cited above). No release data is tracked. Verify downstream.
- Fix last verified (merged) `2026-04-09`. This confirmation is old and may be out of date (a revert/reopen would not have invalidated it here); re-verify.
