openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Dedicated jailed actions directory separate from internal workspace

Open senamakel opened this issue 6 months ago • 3 comments

Summary

Coding and shell tools today treat config.workspace_dir (~/.openhuman/users/<user_id>/workspace/) as the agent's working directory. That path is also where the core stores internal product state — memory DBs, sessions, skills, vault, approval store, transcripts, agent prompts, and more. Agent file/shell actions therefore run in the same tree as config and persistence, which is risky, confusing, and hard to reason about for users and security review.

We should introduce a dedicated actions directory (coding, clones, shell scripts, artifacts) that is jailed by default, and reserve workspace/ for internal OpenHuman state only.

Problem

Who it hurts: Anyone using code_executor, filesystem tools (file_read / file_write / edit / apply_patch / grep / git_operations), shell / node_exec / npm_exec, codegraph_*, or agents prompted to "work in the workspace."

Layout today (authenticated user):

Path Role
~/.openhuman/users/<user_id>/ User-scoped config dir (config.toml, credentials, encryption, etc.) — resolved as openhuman_dir
~/.openhuman/users/<user_id>/workspace/ Config.workspace_dir — single bucket for everything

What already lives under workspace/ (non-exhaustive):

  • memory/, memory_tree/ — conversation + chunk stores
  • sessions/, session_raw/ — agent transcripts
  • vault/, approval/, subconscious/, task_sources/, mcp_clients/
  • skills/, codegraph/, agent/prompts/, PROFILE.md, MEMORY.md
  • Downloads / curl dest subdirs, screenshots, workflow markers (.openhuman/)

How tools use it:

  • SecurityPolicy resolves relative paths against workspace_dir and enforces workspace_only + trusted_roots (src/openhuman/security/policy.rs).
  • shell executes with CWD = security.workspace_dir (src/openhuman/tools/impl/system/shell.rs).
  • Filesystem tools join paths to workspace_dir (file_write, edit_file, git_operations, etc.).
  • code_executor and other coding agents are documented/prompted to operate in a "sandboxed" environment but inherit the same root.

Partial mitigation that does not solve the model:

  • ~/OpenHuman/projects (OPENHUMAN_PROJECTS_DIR, default_projects_dir()) is injected as a trusted root at startup (channels/runtime/startup.rs) — visible user projects live there.
  • cwd_jail (src/openhuman/cwd_jail/) can OS-jail spawned children, but it is a separate layer from the logical workspace root most tools use today.

Why this is a problem:

  1. Safety — A mistaken rm -rf, broad git clean, or runaway script can touch OpenHuman's own databases and session files, not just a clone.
  2. Clarity — Users cannot see a clean "where my code lives" vs "where the app stores state."
  3. Policy — workspace_only is supposed to contain agents; containing the app's memory vault inside that same jail defeats the purpose.
  4. Onboarding — Docs already describe ~/OpenHuman/projects as the coding home (CLAUDE.md / default_projects_dir), but the default tool CWD still points at the internal workspace unless autonomy grants or prompts steer elsewhere.

Solution (optional)

Target layout

~/.openhuman/users/<user_id>/
  config.toml                 # config dir (unchanged)
  workspace/                  # INTERNAL ONLY — memory, sessions, skills, vault, …
  actions/                    # NEW — default jail root for coding + shell (or name TBD)
    projects/                 # optional mirror of ~/OpenHuman/projects semantics
    scratch/                  # ephemeral agent output

Alternative: keep workspace/ internal and default all shell/file tools to default_projects_dir() (~/OpenHuman/projects) with cwd_jail mandatory — but still need a distinct path under the user tree for E2E / multi-tenant consistency.

Behaviour changes

  1. Config — Add actions_dir (or agent_sandbox_dir) to Config / autonomy schema, defaulting to user_dir.join("actions") (created at init). Document vs OPENHUMAN_PROJECTS_DIR.
  2. Tool routing — Filesystem + shell + git + codegraph tools use actions_dir as default CWD and relative-path root; reads of internal state (memory RPC, session resume) continue to use workspace_dir only through dedicated domains — not via file_read("memory/...") from agents unless explicitly allowlisted.
  3. Agents — Update code_executor, tool_maker, and coding-harness prompts to reference the actions root; orchestrator delegates with explicit working directory when spawning repo work.
  4. Jail by default — Wire cwd_jail::spawn for shell / node_exec / npm_exec with Jail::new(actions_dir, …) on supported platforms; noop backend with strict path policy elsewhere.
  5. SecurityPolicy — Split concepts:
    • internal_workspace_dir — read/write for core domains only (not exposed as generic agent write root).
    • actions_dir — agent read/write with workspace_only semantics scoped here.
    • Retain trusted_roots for user-visible ~/OpenHuman/projects.
  6. Migration — One-time move or symlink policy for existing user trees; marker file to avoid re-running; E2E uses isolated OPENHUMAN_WORKSPACE temp dirs (already supported).

Non-goals (initial cut)

  • Moving every internal store out of workspace/ in one PR (can be phased: stop new tool writes into workspace/ first).
  • Replacing Landlock/Seatbelt with a new sandbox product — use existing cwd_jail + policy.

Acceptance criteria

  • [ ] Separate roots — Config exposes a distinct actions/sandbox path; coding/shell tools default to it, not users/<id>/workspace/.
  • [ ] Internal state protected — Agent file_write / shell cannot create or delete under memory/, vault/, sessions/, etc., without an explicit break-glass allowlist (ideally none in v1).
  • [ ] Jailed execution — Shell-family tools run inside cwd_jail (or documented noop + path hardening on unsupported OS) with root = actions dir.
  • [ ] Projects alignment — ~/OpenHuman/projects (trusted root) and per-user actions/ relationship is documented; Settings → Agent access reflects both.
  • [ ] Agent prompts — code_executor (and related) prompts reference the actions directory, not "the workspace" for clones/builds.
  • [ ] Tests — Rust tests: path policy blocks writes to workspace/memory/ from tools rooted at actions; shell CWD assertion. JSON-RPC or harness E2E: run shell with pwd and assert actions path.
  • [ ] Migration — Existing installs get a safe default (create actions/, no data loss in workspace/).
  • [ ] Diff coverage ≥ 80% — implementing PR meets the changed-lines coverage gate.

Related

  • User dir resolution: src/openhuman/config/schema/load.rs (users/<id>/workspace)
  • Security policy: src/openhuman/security/policy.rs
  • Shell CWD: src/openhuman/tools/impl/system/shell.rs
  • OS jail: src/openhuman/cwd_jail/
  • Projects trusted root: default_projects_dir(), channels/runtime/startup.rs
  • Agent access UI: app/src/components/settings/panels/AgentAccessPanel.tsx

senamakel avatar May 31 '26 03:05 senamakel

Audit of merged PR #3074 against this issue's 8 acceptance criteria:

# Criterion Verdict
1 Separate roots MET — Config.action_dir defaults to ~/OpenHuman/projects; all acting tools resolve CWD there (shell.rs:237, node_exec.rs:233, file_write.rs:72, etc.)
2 Internal state protected MET — SecurityPolicy::is_workspace_internal_path() (policy.rs:1097-1132) blocks 16 dirs + 7 secret files, fail-closed via is_path_string_allowed()
3 Jailed execution PARTIAL — cwd_jail:: not invoked from any tool (zero hits under src/openhuman/tools/); path-hardening fallback only, undocumented
4 Projects alignment PARTIAL — AgentAccessPanel.tsx:322-363 shows the split but hard-codes path strings (ignores OPENHUMAN_ACTION_DIR); CLAUDE.md not updated
5 Agent prompts NOT MET — zero prompt files changed in PR #3074; code_executor/prompt.md still says generic "sandboxed environment"
6 Tests PARTIAL — policy_tests.rs:2465-2540 covers path policy, but no shell pwd-asserts-action_dir test and no JSON-RPC E2E entry
7 Migration MET — startup create_dir_all(action_dir), no workspace/ move, no data loss
8 Diff coverage ≥ 80% MET — Coverage Gate job 78894464975 passed

Net: 4 MET, 3 PARTIAL, 1 NOT MET. Filed six follow-ups to close the gaps:

  • #3235 — Wire cwd_jail into shell, node_exec, and npm_exec tools (criterion 3)
  • #3236 — Update coding-agent prompts to reference action sandbox (criterion 5)
  • #3237 — AgentAccessPanel should display live action_dir/workspace_dir via RPC (criterion 4)
  • #3238 — Add pwd-asserts-action_dir test for shell-family tools (criterion 6)
  • #3239 — Document action sandbox vs internal-workspace split in CLAUDE.md (criterion 4)
  • #3240 — Make action_dir editable in Settings UI (beyond strict criteria but called out in PR #3074 body)

Leaving this issue open until the criterion-3 / criterion-5 gaps are closed; the rest are quality-of-life and documentation follow-ups.

CodeGhost21 avatar Jun 02 '26 21:06 CodeGhost21

https://github.com/tinyhumansai- - [ ] /openhuman/pull/3194**[]# # ()**

fzamel3333-ai avatar Jun 02 '26 22:06 fzamel3333-ai

All six follow-ups from the 2026-06-02 audit are now closed:

# Title Closed
#3235 Wire cwd_jail into shell, node_exec, npm_exec (criterion 3) 2026-06-04
#3236 Update coding-agent prompts to reference action sandbox (criterion 5) 2026-06-03
#3237 AgentAccessPanel shows live action_dir / workspace_dir via RPC (criterion 4) 2026-06-03
#3238 pwd-asserts-action_dir test for shell-family tools (criterion 6) 2026-06-03
#3239 Document action sandbox vs internal-workspace split in CLAUDE.md (criterion 4) 2026-06-02
#3240 Make action_dir editable in Settings UI 2026-06-04

Both gating criteria (3 and 5) are resolved. Closing as completed.

CodeGhost21 avatar Jun 13 '26 19:06 CodeGhost21