Skip to content

Commit 2c556e4

Browse files
committed
fix: wire sandbox into MCP server --sandbox actually creates Docker container
mcpCmd parsed --sandbox but never called setupSandbox(), so the flag was silently ignored — shell commands always ran on the host. Now follows the same pattern as runCmd/replCmd/serve/subagent: build sandboxConfig from resolved settings, check resolved.Sandbox, call setupSandbox(), defer cleanup. All existing security hardening (--cap-drop, no-new-privileges, tmpfs, resource limits) applies.
1 parent 96c2b7b commit 2c556e4

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

cmd/kode/mcp.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ Flags:
5757
systemMessage = defaultSystem
5858
}
5959

60+
// Build sandbox config from resolved settings
61+
sbCfg := sandboxConfig{
62+
Image: resolved.SandboxImage,
63+
Network: resolved.SandboxNetwork,
64+
Readonly: resolved.SandboxReadonly,
65+
Memory: resolved.SandboxMemory,
66+
CPUs: resolved.SandboxCPUs,
67+
User: resolved.SandboxUser,
68+
Env: resolved.SandboxEnv,
69+
Volumes: resolved.SandboxVolumes,
70+
}
71+
6072
// Build skills manager (for skill tools)
6173
var sm *skills.SkillManager
6274
if resolved.Skills.Learn {
@@ -69,6 +81,17 @@ Flags:
6981
// Build tools
7082
toolSet := builtinTools(resolved.Dangerous, sm, nil)
7183

84+
// Sandbox setup (must happen after tools are created)
85+
var sandboxCleanup func() error
86+
if resolved.Sandbox {
87+
cleanup, err := setupSandbox(toolSet, sbCfg)
88+
if err != nil {
89+
return fmt.Errorf("sandbox: %w", err)
90+
}
91+
sandboxCleanup = cleanup
92+
defer sandboxCleanup()
93+
}
94+
7295
// Convert to MCP NativeTool slice
7396
var callers []mcp.ToolCaller
7497
for _, t := range toolSet {

0 commit comments

Comments
 (0)