openclaw - 💡(How to fix) Fix [Feature]: Pre-container-creation hook for dynamic sandbox bind mounts [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#61673Fetched 2026-04-08 02:56:07
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Allow a host-side hook (script or callback) to run before a sandbox container is created, enabling dynamic resolution of sandbox.docker.binds based on session context (channel, user, metadata).

Error Message

exit !0 → fail container creation with error

  • Invalid JSON or blocked paths → container creation fails, clear error surfaced to user

Root Cause

Allow a host-side hook (script or callback) to run before a sandbox container is created, enabling dynamic resolution of sandbox.docker.binds based on session context (channel, user, metadata).

Fix Action

Fix / Workaround

Current workarounds and why they fall short:

Code Example

agents:
  defaults:
    sandbox:
      docker:
        resolveBinds: "./scripts/resolve-binds.sh"
        binds: ["/data/shared:/workspace/shared:ro"]  # static, always included

---

stdin:  {"channelId": "C123", "userId": "U456", "agentName": "support-agent"}
stdout: ["/data/confidential:/workspace/confidential:ro"]
exit 0 → merge with static binds
exit !0 → fail container creation with error
RAW_BUFFERClick to expand / collapse

Summary

Allow a host-side hook (script or callback) to run before a sandbox container is created, enabling dynamic resolution of sandbox.docker.binds based on session context (channel, user, metadata).

Problem to solve

In multi-user gateway deployments with differentiated file access (governance levels, compliance tiers, client data isolation), each user session needs a different subset of host directories mounted into its sandbox container.

Today, agents.defaults.sandbox.docker.binds is static per agent config — every session of the same agent gets identical filesystem access. There is no way to vary bind mounts per session based on user identity or channel context.

Concrete scenario: A team gateway routes users via channels. Depending on the user's governance level (derived from channel metadata), the sandbox should only mount the directories that user is authorized to access. User A sees /data/public, user B sees /data/public + /data/confidential.

Current workarounds and why they fall short:

ApproachProblem
One agent per access levelCombinatorial explosion (N levels × M agent configs). Maintenance burden grows linearly.
Mount everything + restrict via setupCommand / ACLsMount points remain visible to the model. Violates least privilege. setupCommand runs inside the container — cannot remove mounts.
External wrapper rewriting config before gateway startRace conditions with concurrent sessions. Config reload may affect other active sessions.
before_agent_start plugin hookRuns after container creation. Cannot influence bind mounts. Cannot cancel session (#19420).

Proposed solution

Add an optional sandbox.docker.resolveBinds config field pointing to a host-side executable. The gateway invokes it before container creation, passing session context on stdin. The script returns bind mount entries on stdout.

agents:
  defaults:
    sandbox:
      docker:
        resolveBinds: "./scripts/resolve-binds.sh"
        binds: ["/data/shared:/workspace/shared:ro"]  # static, always included

Script contract:

stdin:  {"channelId": "C123", "userId": "U456", "agentName": "support-agent"}
stdout: ["/data/confidential:/workspace/confidential:ro"]
exit 0 → merge with static binds
exit !0 → fail container creation with error

Security constraints (same validation as static binds):

  • Output validated against existing blocklist (/etc, /proc, /sys, docker.sock, credential dirs)
  • Timeout enforced (e.g. 5 seconds) to prevent gateway hangs
  • Invalid JSON or blocked paths → container creation fails, clear error surfaced to user

Alternatives considered

  • One agent per access level: Works but scales poorly (N governance levels × M agent configs). Maintenance burden grows linearly.
  • Mount everything + restrict via setupCommand: Mount points remain visible to the agent even if ACLs block reads. Violates principle of least privilege. A sufficiently capable model might attempt to circumvent in-container restrictions.
  • External wrapper that rewrites config before gateway start: Race conditions with concurrent sessions. Config reloads during active sessions could affect other users.
  • Plugin before_agent_start hook: Runs after container creation, cannot influence bind mounts. Also currently cannot cancel session start (#19420, closed as not planned).

Impact

  • Affected: Any multi-user OpenClaw deployment with differentiated file access (compliance-driven teams, consulting firms with client data isolation, multi-tenant SaaS platforms)
  • Severity: Blocks workflow — currently no secure way to run governance-level file isolation per session
  • Frequency: Every session start in affected deployments
  • Consequence: Either all users get access to all files (security risk) or operators maintain N duplicate agent configs (operational burden)

Evidence/examples

  • Comparable patterns: Kubernetes admission webhooks (mutate pod specs including volume mounts before scheduling), VS Code Dev Containers initializeCommand (runs on host before container creation), Docker Compose profiles (conditional service configuration based on environment)
  • Related issues: #30334 (plugin config injection — similar need for dynamic per-session container config), #22669 (bind mount ordering — shows binds are already a friction point), #19420 (before_agent_start cannot cancel sessions — closed as not planned)

Additional information

  • The hook must run on the host (not inside the container) since it determines container creation parameters.
  • Should be composable with static binds (merge by default, with an option to replace).
  • A TypeScript function alternative (instead of external script) could integrate more tightly with gateway internals but reduces deployment flexibility.

extent analysis

TL;DR

Implement a host-side hook, such as a script or callback, to dynamically resolve sandbox.docker.binds based on session context before creating a sandbox container.

Guidance

  • To address the issue, introduce an optional sandbox.docker.resolveBinds config field pointing to a host-side executable that the gateway invokes before container creation.
  • Ensure the script contract is followed, where the script receives session context on stdin and returns bind mount entries on stdout.
  • Validate the script's output against existing blocklists and enforce a timeout to prevent gateway hangs.
  • Consider implementing a TypeScript function alternative for tighter integration with gateway internals, while weighing the trade-offs with deployment flexibility.

Example

agents:
  defaults:
    sandbox:
      docker:
        resolveBinds: "./scripts/resolve-binds.sh"
        binds: ["/data/shared:/workspace/shared:ro"]

Notes

The proposed solution requires careful consideration of security constraints, such as output validation and timeout enforcement, to prevent potential security risks.

Recommendation

Apply the proposed workaround by introducing the sandbox.docker.resolveBinds config field and implementing the host-side hook, as it provides a flexible and secure way to dynamically resolve sandbox.docker.binds based on session context.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix [Feature]: Pre-container-creation hook for dynamic sandbox bind mounts [1 participants]