Skip to content

fix: sandbox path mounting and workspace isolation (#129, #136)#137

Open
Erudition wants to merge 21 commits intonextlevelbuilder:mainfrom
Erudition:fix-issue-129-sandbox-workspace-path
Open

fix: sandbox path mounting and workspace isolation (#129, #136)#137
Erudition wants to merge 21 commits intonextlevelbuilder:mainfrom
Erudition:fix-issue-129-sandbox-workspace-path

Conversation

@Erudition
Copy link

@Erudition Erudition commented Mar 11, 2026

Description

This PR addresses several critical issues related to sandbox path mounting and agent workspace isolation in Docker environments. Prior to these fixes, the sandbox was effectively unusable in many Docker-based deployments (such as Portainer) because hardcoded default paths (like /.goclaw/...) were not correctly mapped to persistent volumes, leading to chdir failures and sandbox startup errors.

1. Fix Docker Volume Mounting Issues (Issue #129)

  • Problem: Sandbox containers were failing to start because they couldn't find the workspace directory. Inside Docker, ~ was expanding to ephemeral locations instead of the persistent /app/workspace mount.
  • Dynamic Path Resolution: Implemented resolveHostWorkspacePath to dynamically discover the host volume or path for container directories like /app/workspace. This allows sibling containers in DooD (Docker-out-of-Docker) environments to mount the correct volumes.
  • Legacy Path Migration: Added MigrateLegacyPath to automatically re-route old ~/.goclaw paths to the persistent volume mount, ensuring backward compatibility.
  • Default Workspaces: Updated the system to ensure new agents receive valid default workspace paths and existing agents with empty fields are proactively fixed.

2. Fix Sandbox Isolation Breach (Issue #136)

  • Problem: Filesystem tools were defaulting to the global workspace root, allowing agents to potentially access files belonging to other agents.
  • Shared Path Mapping: Introduced MapHostPathToSandbox utility to ensure all filesystem tools (exec, read, write, list, edit) consistently resolve paths relative to the agent's dedicated container-side subdirectory.
  • Escape Prevention: Implemented strict checks to block any attempts to access paths outside the agent's specific subdirectory within the sandbox.

3. Nginx DNS Caching Fix

  • Updated ui/web/nginx.conf to use Docker's internal DNS resolver (127.0.0.11) with dynamic upstream resolution. This prevents "Host unreachable" errors in the UI when the backend container is recreated with a new internal IP.

4. Build Fix

  • Removed an unused path/filepath import in internal/tools/shell.go.

Verification

  • Verified successful compilation: go build -o goclaw .
  • Verified path resolution logic in the sandbox manager.
  • Manual verification of agent workspace isolation through tool calls.

@Erudition Erudition mentioned this pull request Mar 11, 2026
@Erudition
Copy link
Author

Also touches on #46

@Erudition Erudition force-pushed the fix-issue-129-sandbox-workspace-path branch from 4147b17 to ce39d69 Compare March 11, 2026 09:22
… hardcoded '/workspace'

Fixes nextlevelbuilder#129 by injecting the SandboxContainerDir configuration from the
agent loop into the tool context. The Execute functions for shell, file
read/write, and edit tools now dynamically use this directory path
instead of the literal string '/workspace'. Fallback to '/workspace'
is preserved if the path is missing from ctx.
…CE_PATH

Plumbs the Workdir field into SandboxConfig and parses the
GOCLAW_SANDBOX_WORKSPACE_PATH environment variable so that users
can override the default '/workspace' path dynamically.
When GoClaw runs in a Docker container (e.g. via docker-compose) and spawns
sibling sandbox containers, passing the internal container path (e.g. /app/workspace)
to the Docker daemon causes the daemon to mount a non-existent host path.
This commit dynamically inspects the container's own mounts to determine
the true host volume/path corresponding to the workspace, ensuring sandboxes
start with the correct code rather than an empty directory.
…DNS tools

- Added ctxSandboxNetwork context key and helpers in internal/tools/context_keys.go
- Propagated SandboxNetworkEnabled flag through LoopConfig, Loop, and ManagedResolver
- Injected sandbox network status into tool context in internal/agent/loop.go
- Updated ExecTool in internal/tools/shell.go to conditionally allow dnsutils (nslookup, dig, host) when sandbox networking is enabled
- Updated cmd/gateway_managed.go to initialize SandboxNetworkEnabled from app configuration
- Added regression tests for ExecTool security policy in internal/tools/shell_test.go
- Fixed redeclaration error in internal/tools/shell.go
- Finalized sandbox networking propagation and adaptive security policy
- Rebuilt sandbox image with dnsutils and iputils-ping
Add a sandbox-image service with deploy.replicas=0 to
docker-compose.sandbox.yml so that 'docker compose up --build'
automatically rebuilds goclaw-sandbox:bookworm-slim when
Dockerfile.sandbox changes. Docker layer caching makes this
near-instant when the Dockerfile hasn't changed.

This removes the manual 'docker build' prerequisite step
and updates the usage instructions accordingly.
DockerManager.Get() was using the singleton manager config with
NetworkEnabled=false for all containers, ignoring the per-agent
'Network Enabled' toggle completely (Issue nextlevelbuilder#139 root cause nextlevelbuilder#2).

Changes:
- sandbox: add WithNetworkOverride/NetworkOverrideFromCtx context
  helpers so callers can override the manager's default network
  setting per-request
- DockerManager.Get(): read the context override and clone the
  config before creating a container; append '-net' to the cache
  key so agents with networking get a separate container from those
  without (avoids reusing a --network=none container)
- tools: inject sandbox.WithNetworkOverride(ctx, true) before each
  sandboxMgr.Get() call in all 5 sandboxed tools (shell, read_file,
  write_file, list_files, edit_file) when ToolSandboxNetworkFromCtx
  is true
…form

- Improved argument parsing to use shell-style splitting instead of comma-separated.
- This allows users to enter standard CLI flags and handle values with spaces using quotes.
- Updated English translations to reflect the new format.
@Erudition Erudition force-pushed the fix-issue-129-sandbox-workspace-path branch from ce39d69 to 50b0071 Compare March 11, 2026 15:42
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.

1 participant