Skip to content

feat: add per-agent sandbox and tool configuration#380

Merged
steipete merged 15 commits intoopenclaw:mainfrom
pasogott:feature/per-agent-sandbox-tools
Jan 7, 2026
Merged

feat: add per-agent sandbox and tool configuration#380
steipete merged 15 commits intoopenclaw:mainfrom
pasogott:feature/per-agent-sandbox-tools

Conversation

@pasogott
Copy link
Copy Markdown
Contributor

@pasogott pasogott commented Jan 7, 2026

Per-Agent Sandbox and Tool Configuration

Motivation

This PR enables multi-agent setups with different security profiles - a real-world need when running multiple agents with varying trust levels.

Use case: Personal assistant with full system access vs. family group chat bot with restricted permissions.

Implementation

Very minimal changes (49 LoC across 5 files):

  • Types + validation for routing.agents[].sandbox and routing.agents[].tools
  • Agent-specific config resolution in defaultSandboxConfig() and tool filtering
  • 18 new tests, all existing 1325 tests still pass ✅

Example Config

{
  "routing": {
    "agents": {
      "main": {
        "workspace": "~/clawd",
        "sandbox": { "mode": "off" }
      },
      "family": {
        "workspace": "~/clawd-family",
        "sandbox": { "mode": "all", "scope": "agent" },
        "tools": { "allow": ["read"], "deny": ["bash", "write", "edit"] }
      }
    }
  }
}

Result:

  • main agent: Host, all tools available
  • family agent: Docker container, read-only

Backward Compatibility

✅ 100% backward compatible - new fields are optional, defaults to global config

Testing

  • ✅ 18 new tests (agent-scope, sandbox-agent-config, pi-tools-agent-config)
  • ✅ All 1325 existing tests pass
  • ✅ Verified with Discord, Telegram, WhatsApp providers

Documentation

  • New guide: docs/multi-agent-sandbox-tools.md
  • Updated: docs/concepts/multi-agent.md
  • Updated: docs/gateway/configuration.md

Kudos to Eula 🦉, the beautiful and selfless family owl who inspired this feature! This enables safe, restricted access for family group chats while maintaining full control for the personal assistant. Schuhu!

Looking forward to feedback! Happy to adjust the approach if there's a preferred pattern.

@imfing
Copy link
Copy Markdown
Contributor

imfing commented Jan 7, 2026

Nice, this looks like a better version of my PR #351 👍 Will close mine

sheeek added 11 commits January 7, 2026 12:09
Add optional per-agent configuration:
- sandbox: { mode, scope, perSession, workspaceRoot }
- tools: { allow, deny }

These will allow agents to override global agent.sandbox and
agent.tools settings.
Validate per-agent sandbox config:
- mode: 'off' | 'non-main' | 'all'
- scope: 'session' | 'agent' | 'shared'
- perSession: boolean
- workspaceRoot: string

Validate per-agent tools config:
- allow: string[]
- deny: string[]
Return newly added fields from routing.agents config:
- sandbox: agent-specific sandbox configuration
- tools: agent-specific tool restrictions

This makes per-agent sandbox and tool settings accessible
to other parts of the codebase.
Changes to defaultSandboxConfig():
- Add optional agentId parameter
- Load routing.agents[agentId].sandbox if available
- Prefer agent-specific settings over global agent.sandbox

Update callers in resolveSandboxContext() and
ensureSandboxWorkspaceForSession() to extract agentId
from sessionKey and pass it to defaultSandboxConfig().

This enables per-agent sandbox modes (e.g., main: off, family: all).
Add tool filtering layer for per-agent restrictions:
- Extract agentId from sessionKey
- Load routing.agents[agentId].tools via resolveAgentConfig()
- Apply agent-specific allow/deny before sandbox filtering

Filtering order:
1. Global (agent.tools)
2. Agent-specific (routing.agents[id].tools) ← NEW
3. Sandbox (agent.sandbox.tools)
4. Subagent policy

This enables different tool permissions per agent
(e.g., main: all tools, family: read only).
Add 7 tests for resolveAgentConfig():
- Return undefined when no agents config exists
- Return undefined when agent id does not exist
- Return basic agent config (name, workspace, agentDir, model)
- Return agent-specific sandbox config
- Return agent-specific tools config
- Return both sandbox and tools config
- Normalize agent id

All tests pass.
Add 6 tests for agent-specific sandbox configuration:
- Use global sandbox config when no agent-specific config exists
- Override with agent-specific sandbox mode 'off'
- Use agent-specific sandbox mode 'all'
- Use agent-specific scope
- Use agent-specific workspaceRoot
- Prefer agent config over global for multiple agents

All tests pass.
Add 5 tests for agent-specific tool restrictions:
- Apply global tool policy when no agent-specific policy exists
- Apply agent-specific tool policy
- Allow different tool policies for different agents
- Combine global and agent-specific deny lists
- Work with sandbox tools filtering

All tests pass.
Update routing.agents section:
- Add sandbox field documentation (mode, scope, workspaceRoot)
- Add tools field documentation (allow, deny)
- Note that agent-specific settings override global config
Add new section explaining:
- How to configure per-agent sandbox settings
- How to configure per-agent tool restrictions
- Benefits (security isolation, resource control, flexible policies)
- Link to detailed guide

Include example config showing personal assistant (no sandbox)
vs family bot (sandboxed with read-only tools).
Add docs/multi-agent-sandbox-tools.md covering:
- Configuration examples (personal + restricted, work agents)
- Different sandbox modes per agent
- Tool restriction patterns (read-only, safe execution, communication-only)
- Configuration precedence rules
- Migration guide from single-agent setups
- Troubleshooting tips

Add PR_SUMMARY.md for upstream submission with:
- Feature overview and use cases
- Implementation details (49 LoC across 5 files)
- Test coverage (18 new tests, all existing tests pass)
- Backward compatibility confirmation
- Migration examples

---

Kudos to Eula, the beautiful and selfless family owl 🦉
This feature was developed to enable safe, restricted access
for family group chats while maintaining full access for
the personal assistant. Schuhu!
@steipete
Copy link
Copy Markdown
Contributor

steipete commented Jan 7, 2026

Thanks Clawtributor! This misses the new workspaceAccess I added earlier today, but will weave in.

@steipete steipete self-assigned this Jan 7, 2026
@steipete
Copy link
Copy Markdown
Contributor

steipete commented Jan 7, 2026

Landed on main (PR commits were already patch-equivalent on main). Follow-ups on main: 090390c (agent tools override + sync bash without process), fd87290 (clawtributors avatar), 48a333d (bash warnings init), 5b97fea (process sessions scoped per agent).

@steipete
Copy link
Copy Markdown
Contributor

steipete commented Jan 7, 2026

Already landed on main (patch-equivalent). See comment for follow-up SHAs.

@steipete steipete closed this Jan 7, 2026
@steipete steipete reopened this Jan 7, 2026
@steipete steipete merged commit c21ba9e into openclaw:main Jan 7, 2026
@steipete
Copy link
Copy Markdown
Contributor

steipete commented Jan 7, 2026

Merged after updating branch with origin/main (merge commit abf43f6) and keeping main’s conflict resolutions. Main already contained the functional commits: 090390c, 5b97fea, 48a333d, fd87290.

dgarson added a commit to dgarson/clawdbot that referenced this pull request Feb 9, 2026
…penclaw#380)

* Web: honor live sessions and agent status gating

* Web: disable status toggles when gateway connected
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…ox-tools

feat: add per-agent sandbox and tool configuration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants