Skip to content

HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.

fix(runner): the wrong folder must not exist — the session workspace IS the workspace root on per-session sandboxes

richard-epsillab9a7573c3fd6
diff --git a/runner/server.py b/runner/server.py
index 77da963b..1b107776 100644
--- a/runner/server.py
+++ b/runner/server.py
@@ -75,6 +75,13 @@ WORKSPACE_ROOT = os.environ.get("HARNESS_WORKSPACE", "/workspace")
_SID_SAFE = re.compile(r"[^A-Za-z0-9._-]")
+# "One sandbox per session" as a DEPLOYMENT INVARIANT, declared by the deployment itself (the
+# hosted session pool sets it: ACA Dynamic Sessions gives each identifier its own
+# Hyper-V-isolated container). Everything it changes fails CLOSED when unset — the self-hosted
+# all-in-one container runs ONE runner for ALL sessions, where these behaviors would break
+# session isolation. See _ws() and _reap_workspaces().
+_SANDBOX_PER_SESSION = os.environ.get("HR_SANDBOX_PER_SESSION", "").strip().lower() in ("1", "true", "on")
+
# How long an untouched session workspace is kept. Sessions are resumable from their checkpoint,
# so a reaped directory costs a rehydrate, not the work — but keeping every one forever fills the
# disk of a box nobody is watching. 0 disables.
@@ -84,6 +91,11 @@ WS_TTL_HOURS = float(os.environ.get("HR_WORKSPACE_TTL_HOURS", "72") or 0)
def _reap_workspaces(keep: str = "") -> int:
"""Delete session workspaces untouched for longer than the TTL. Cheap, and only ever called
at hydrate — the moment we already know a session is starting fresh."""
+ if _SANDBOX_PER_SESSION:
+ # The workspace root IS the session workspace (see _ws): iterating it would reap the
+ # session's own project subdirectories as if they were idle sessions. The sandbox's own
+ # lifecycle (pool cooldown) is the cleanup mechanism in this mode.
+ return 0
if WS_TTL_HOURS <= 0:
return 0
cutoff = time.time() - WS_TTL_HOURS * 3600
@@ -121,8 +133,23 @@ def _ws(identifier: str = "") -> str:
false: /hydrate wipes and restores, so two sessions would destroy each other's files.
The gateway already addresses every runner call as ?identifier=<session_id>, so the session
- id IS the directory and nothing on the wire changes. Hosted keeps one session per sandbox
- and simply lands in one subdirectory."""
+ id IS the directory and nothing on the wire changes.
+
+ UNDER THE PER-SESSION-SANDBOX INVARIANT (HR_SANDBOX_PER_SESSION, declared by the hosted
+ pool: each identifier gets its own Hyper-V-isolated container), the session workspace IS
+ WORKSPACE_ROOT itself. This is the mechanical fix for deliverables written to "/workspace/X"
+ — the path models reach for when told they work in a workspace. With a per-session
+ subdirectory, that path was a writable trap OUTSIDE the git tree: never collected, never
+ checkpointed, invisible to the user (two live incidents on 2026-08-21, deepseek family,
+ one of them DESPITE the AGENTS.md contract — an instruction binds only models that follow
+ instructions). With the root as the workspace, the wrong folder does not exist: /workspace/X
+ is inside the collected tree by construction. No instruction, no post-hoc adoption (an
+ adoption pass on a SHARED root would be a cross-session attack plane: name, content and
+ mtime of a stray file are all attacker-controlled). Shared deployments (self-host: one
+ runner, many sessions) keep per-session subdirectories, because there they ARE the
+ session isolation."""
+ if _SANDBOX_PER_SESSION:
+ return WORKSPACE_ROOT
sid = _SID_SAFE.sub("_", (identifier or "").strip())[:120] or "_default"
return os.path.join(WORKSPACE_ROOT, sid)
# Where checkpoint/hydrate tarballs spool to disk (HR-INF-015 — never a RAM buffer). MUST be
@@ -2500,44 +2527,11 @@ def checkpoint(background_tasks: BackgroundTasks, identifier: str = "") -> Respo
raise
-def _adopt_stray_root_files(ws: str) -> None:
- """Move files the agent left at WORKSPACE_ROOT itself into the session workspace.
-
- The sandbox is single-session, so a file at the workspace PARENT was written by this
- session's agent — but it sits outside the git tree, so collection, the checkpoint and the
- console cannot see it, and it silently dies with the sandbox. This is not hypothetical:
- both live incidents (2026-08-21, deepseek family on dsh) answered "saved to
- /workspace/X.pptx" with the deliverable exactly there, ONCE DESPITE the AGENTS.md
- workspace contract — an instruction binds only models that follow instructions. So the
- collection boundary is made mechanical instead: adopt top-level regular files (never
- directories — session workspaces live here; never dotfiles — internal by convention)
- into the session dir before git status runs. A name that already exists in the workspace
- is left alone: the copy the agent placed correctly is authoritative."""
- try:
- entries = list(os.scandir(WORKSPACE_ROOT))
- except OSError:
- return
- for e in entries:
- try:
- if not e.is_file(follow_symlinks=False) or e.name.startswith("."):
- continue
- if e.name in _PRODUCED_EXCLUDE_NAMES or _is_produced_noise(e.name):
- continue
- dest = os.path.join(ws, e.name)
- if os.path.exists(dest):
- continue
- shutil.move(e.path, dest)
- print(f"[produced] adopted stray {e.name} from the workspace root", flush=True)
- except OSError:
- continue
-
-
@app.get("/produced")
def produced(identifier: str = "") -> dict:
"""Files created/modified during the current turn (uncommitted vs the hydrated checkpoint).
Call BEFORE /checkpoint commits them. Excludes internal state / scratch / secrets / vcs."""
ws = _ws(identifier)
- _adopt_stray_root_files(ws)
_git_ensure(ws)
p = _git(ws, "status", "--porcelain", "-uall")
out = []