Adding sandbox for linux#14
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a Linux-only Bubblewrap-backed sandbox for run_command, shifting command execution from a string-based allowlist to an explicit argv vector plus sandbox “mode”, and surfacing startup warnings when sandboxing is unavailable.
Changes:
- Add
plain_agent.sandboxtypes and a Bubblewrap backend with offline + workspace policy enforcement. - Update
run_commandtool + runtime to execute validatedargvthrough the sandbox and adjust approval UX to show exact quoted argv + requested mode. - Add extensive unit + Linux integration tests and a GitHub Actions workflow that installs Bubblewrap and runs the full test suite.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_tools.py | Updates tool and runtime tests to use argv + sandbox backend stubs and adds coverage for output retention. |
| tests/test_textual_terminal.py | Adds coverage for rendering command-approval output and startup warnings in the Textual UI. |
| tests/test_terminal_loop.py | Updates approval flow tests to pass CommandRequest and verifies warning output in the basic terminal loop. |
| tests/test_sandbox.py | Adds unit tests for sandbox types, Bubblewrap command construction, discovery behavior, and parse/read-roots validation. |
| tests/test_linux_sandbox.py | Adds Linux integration tests verifying Bubblewrap enforcement (workspace RO/WR, no net, secret masking, timeouts). |
| tests/test_agent.py | Updates agent tests to the argv interface and injects a sandbox-backed Tools for deterministic behavior. |
| README.md | Documents Bubblewrap installation, sandbox behavior/modes, and read-root configuration. |
| plain_agent/ui/textual_terminal/rendering.py | Adds format_command_approval and uses CommandRequest for consistent user-visible rendering. |
| plain_agent/ui/textual_terminal/app.py | Displays startup warnings on mount and updates the approval prompt to use CommandRequest. |
| plain_agent/tools/tools.py | Adds auto-discovery of Linux sandbox, startup warnings, and omits run_command when sandbox is unavailable. |
| plain_agent/tools/run_command.py | Changes tool schema from command to {argv, mode} and routes execution via the sandboxed runtime. |
| plain_agent/tools/command_runtime.py | Replaces allowlist parsing with sandbox backend invocation and threaded stdout/stderr draining + truncation. |
| plain_agent/tools/command_policy.py | Removes the old command allowlist policy module (no longer used). |
| plain_agent/terminal_loop.py | Updates approval prompt formatting to include mode and exact quoted argv. |
| plain_agent/sandbox/bubblewrap.py | Implements Bubblewrap command construction, env filtering, workspace protections, and backend discovery/probing. |
| plain_agent/sandbox/base.py | Adds shared sandbox types (CommandRequest, SandboxMode, backend protocol, error types). |
| plain_agent/sandbox/init.py | Exposes the sandbox public API from the package. |
| plain_agent/agent_loop.py | Threads CommandRequest through approval flow, supports injecting Tools, and exposes startup warnings. |
| .github/workflows/test.yml | Adds CI job on Ubuntu that installs Bubblewrap and runs unittest discovery. |
| .env.example | Documents PLAIN_AGENT_SANDBOX_READ_ROOTS. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+49
to
+53
| process = subprocess.Popen( | ||
| sandboxed_argv, | ||
| cwd=request.workspace, | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, |
Comment on lines
+135
to
+143
| def probe(self, timeout_seconds: float = 2) -> None: | ||
| true_path = _first_existing(Path("/usr/bin/true"), Path("/bin/true")) | ||
| if true_path is None: | ||
| raise SandboxUnavailableError("Bubblewrap probe could not find the 'true' executable") | ||
| request = CommandRequest( | ||
| argv=(str(true_path),), | ||
| mode=SandboxMode.READ_ONLY, | ||
| workspace=Path.cwd().resolve(), | ||
| ) |
Comment on lines
+293
to
+309
| def _sensitive_workspace_files(workspace: Path) -> list[Path]: | ||
| sensitive: list[Path] = [] | ||
| skipped_dirs = set(HIDDEN_WORKSPACE_DIRS) | ||
| for root, dirs, files in os.walk( | ||
| workspace, | ||
| followlinks=False, | ||
| onerror=_raise_walk_error, | ||
| ): | ||
| dirs[:] = [name for name in dirs if name not in skipped_dirs] | ||
| root_path = Path(root) | ||
| for name in files: | ||
| lower_name = name.lower() | ||
| path = root_path / name | ||
| if lower_name in SENSITIVE_FILE_NAMES or path.suffix.lower() in SENSITIVE_FILE_SUFFIXES: | ||
| _reject_protected_symlink(path) | ||
| sensitive.append(path) | ||
| return sorted(sensitive) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.