Lesson 09: Shell Tool Security and Sandbox Gates
Enforce a rigorous 3-layer security gate (safe, blocked, and HITL-approved) for shell execution, complete with sensitive environment redaction and synthesis fallback.
1. Why This Feature Exists
Allowing LLMs to run arbitrary shell commands is an extreme security liability. Merci SDK provides a declarative 3-layer security boundary that intercepts commands before process spawning.
2. Key Symbols and Exports
3. Implementation Walkthrough
import {
ProviderType,
resolveProvider,
initializeClient,
loadCredentials,
getToolModel
} from 'merci-sdk';
import { createShellTool } from 'merci-sdk/tools';
const PROVIDER = resolveProvider();
const { client } = await initializeClient({ provider: PROVIDER, options: loadCredentials({ provider: PROVIDER }) });
const shellTool = createShellTool({
cwd: process.cwd(),
allowedCommands: ['ls', 'git status', 'cat', 'grep', 'node -v'],
blockedCommands: ['rm', 'mkfs', 'dd', 'curl', 'wget', 'printenv'],
requireApproval: ['git commit', 'npm install', 'pnpm add']
});
const session = client.session(getToolModel({ provider: PROVIDER }))
.withTools([shellTool] });
const result = await session.run('List the files in the current directory and check git status.');
console.log(result);4. Wire and Telemetry Mechanics
When the model attempts a shell call, the command is tokenized and matched against the security policy. Blocked commands reject immediately with a security violation error; approved commands execute via child_process.spawn.
5. Run the Example
Execute the runnable example directly from the repository root:
node examples/14_coding_agent.mjsRead the full example: examples/14_coding_agent.mjs →