How FinShield makes Git Bash work in a Windows sandbox
Originally published on the FinShield technical blog. Authorized reprint by the FinShield team at Finogeeks. Original article. On DEV this follows How FinShield makes Agent tool chains work inside AppContainer.
How FinShield makes Git Bash work in a Windows sandbox
Previous article: Agent tool chains and AppContainer · Technical blog
Recorded experiments · Windows execution isolation · 2026-11-30
1 Windows has cmd and PowerShell. Why do Agents also use Git Bash?
WorkBuddy and Hermes both use Git Bash when running tasks on Windows. Ask an Agent to organize documents, process a spreadsheet or run a project, and it may first write a Shell command, then use Git Bash to start Python, Node.js and other tools. The Hermes documentation explicitly states that its terminal tool runs commands through Git Bash on Windows so it can reuse its existing cross-platform tools. The CodeBuddy tool chain used by WorkBuddy also recommends installing Git Bash and supports an explicit Bash path. Hermes Windows execution guide · CodeBuddy Git Bash documentation
Windows already has command-line environments, so why install another Bash? It helps to distinguish the common choices:
| Execution environment | What it provides | What an Agent needs to account for |
|---|---|---|
| cmd | The traditional Windows command interpreter for batch files and native programs | Its command syntax, quoting and variables differ from Bash |
| PowerShell | A Shell for Windows administration, with pipelines that can pass objects | Well suited to system administration, but Bash scripts usually need rewriting |
| Git Bash | Bash and a set of Unix tools provided by Git for Windows | Reuses Shell scripts while also calling native Windows programs |
| Bash in WSL | Bash and tools in a Linux environment | Requires handling differences in paths, environments and tools between Linux and Windows |
Agents often choose Git Bash to reuse existing commands and scripts. For example, printf produces text, tr changes its case, cat reads files, | passes one program's output to another, and > writes results to a file. These combinations are common in Linux and macOS tool chains. Git Bash makes the same patterns available on Windows, with native Python or Node.js programs callable from the same execution chain. Git for Windows introduction to Git Bash
Although its name includes “Git,” we are using the Bash command execution environment it provides, independently of Git's version-control features. Agents use it to organize files, process data and start Python or Node.js for everyday tasks. We want to verify whether commands that normally work can still execute and return results to an Agent after it enters a Windows sandbox.
2 Why does Bash encounter AppContainer compatibility problems?
The previous article examined Python and Node.js child-process calls. FinShield uses AppContainer, or AC, as a foundation for Windows protection so that existing tools can run locally while the operating system checks resource access against the process identity. Placing an Agent and its tools inside this permission boundary needs to restrict access to unauthorized resources while keeping the execution mechanisms required for authorized work functional.
Git Bash adds another runtime that needs compatibility work. Bash exposes familiar Unix commands, paths and process behavior, while the programs underneath run on Windows. The MSYS runtime bridges these differences, including shared state, process creation and coordination between tools. Permission to read bash.exe therefore does not establish that all conditions required for Bash initialization and execution have been met.
One specific obstacle involves Windows named objects. MSYS creates object directories used for process coordination. Some calls in the original runtime use the global namespace, where AC also restricts access. These object directories are different from ordinary folders on disk: adding read and write permissions to an experiment directory does not directly resolve namespace access. Microsoft's public MXC issue and the upstream MSYS adaptation describe this initialization path. MXC issue 1061 · MSYS AppContainer adaptation
We start with the simplest Bash commands, then examine subshells, pipes, file operations and calls between Bash and Python or Node.js, before moving to actual Agent Shell entries. Ordinary processes establish that the scripts work; native AC, Microsoft MXC and FinShield provide the restricted environments for comparison.
3 Start with the simplest Bash calls
First, set aside the Agent, model and business task. Test one basic operation: start Bash, execute a command, collect its output and confirm that it exits normally. Then add pipes, file access and calls from Python or Node.js to see whether a failure occurs during startup, command execution or result collection.
3.1 Bash startup: even the version query encounters access denied
The first case executes bash.exe --version and only expects Bash to print its version and exit. Next, the built-in printf command prints one line, without needing to start an external tool. The following commands are tested separately:
bash.exe --version bash.exe --noprofile --norc -c "printf 'BUILTIN_OK\n'" --noprofile --norc prevents personal Shell startup scripts from loading, keeping the case dependent on Bash itself. The version query returns normally in an ordinary process. Under native AC, neither case produces the expected output, and stderr contains the same initialization error:
*** fatal error - NtCreateDirectoryObject(\BaseNamedObjects\msys-2.0S5-2013b3eca82edb8a): 0xC0000022 Here, NtCreateDirectoryObject creates a directory in the Windows object namespace for the objects MSYS shares between processes. It does not create a folder on disk. 0xC0000022 means access denied: the original MSYS runtime attempts to create this directory in the global namespace, and the AC identity lacks the required access. Bash stops during runtime initialization, before it reaches the printf command. A command can therefore encounter a compatibility problem even when it accesses no business files.
3.2 Pipes and redirection: common commands also stop during initialization
Next, we check command combinations that Agents commonly use. The pipeline case has printf produce lowercase text and passes it to the external tr program, requiring the parent process to receive PIPELINE_OK:
printf 'pipeline_ok\n' | /usr/bin/tr a-z A-Z The redirection case writes text to a file, reads it back through stdin with cat, and sends another marker to stderr. It checks file contents, standard input, standard output and error output together:
printf 'REDIRECT_OK\n' > redirected.txt /usr/bin/cat < redirected.txt printf 'STDERR_OK\n' >&2 Both cases complete their expected flows in ordinary processes. The results, organized by output stream, are:
Pipeline case: stdout: PIPELINE_OK returncode: 0 Redirection case: stdout: REDIRECT_OK stderr: STDERR_OK redirected.txt contents: REDIRECT_OK returncode: 0 Under native AC, both cases again record the NtCreateDirectoryObject access denial. They produce none of these task outputs, and the redirection case does not produce the required file contents. The failure still occurs during Bash initialization, before the test reaches conversion by tr or file reading by cat. These different commands all depend on the same MSYS runtime starting successfully.
We also run separate cases for external commands, subshells, command substitution, background tasks and waiting, nested Bash, environment variables, conditional execution, expected nonzero exits, paths containing spaces and Chinese characters, and the working directory. All 16 cases that start Bash directly pass in ordinary processes; none completes its expected flow under native AC.
3.3 Python starts Bash: the child still stops during MSYS initialization
An actual Agent generally starts a Shell from its own runtime and collects the output. The Python case therefore asks Bash only to print INTEROP_OK, rather than executing a complex script. Its core call is:
import os import subprocess p = subprocess.run( [ os.environ["MSYS_LAB_BASH"], "--noprofile", "--norc", "-c", "printf 'INTEROP_OK\\n'", ], capture_output=True, timeout=12, ) MSYS_LAB_BASH points to the fixed Bash executable. capture_output=True collects stdout and stderr in Python, while timeout=12 limits how long this call waits. In an ordinary process, Python receives INTEROP_OK and the child exits with code 0. Under native AC, the marker is absent and stderr contains a Bash initialization error:
NtCreateDirectoryObject(\BaseNamedObjects\msys-2.0S5-2013b3eca82edb8a): 0xC0000022 This call has reached Bash. Changing the parent process has not removed MSYS's need to access named objects. For an Agent, successfully starting Python establishes that the first part of the execution chain works; the Shell and tools it calls must also have the conditions they require.
3.4 Node.js starts Bash: the file entry fails before the call begins
The Node.js case uses child_process.spawn() to start the same Bash executable and collect output through pipes. The core startup and output collection code is:
import { spawn } from 'node:child_process'; const child = spawn( process.env.MSYS_LAB_BASH, ['--noprofile', '--norc', '-c', "printf 'INTEROP_OK\\n'"], { stdio: ['ignore', 'pipe', 'pipe'] }, ); child.stdout.pipe(process.stdout); child.stderr.pipe(process.stderr); The ordinary-process case receives INTEROP_OK and exits normally. Under native AC, however, Node fails while resolving the entry file's path, before reaching this code. The actual error is:
Error: EPERM: operation not permitted, lstat 'D:\' lstat checks path metadata. Access to the drive-root metadata check is denied here, before Bash is called. This failure occurs at a different stage from MSYS initialization: the Python call reaches Bash, while this Node case stops at the parent runtime's file entry.
Together with the 16 direct calls, these two interoperability cases give 18 passes in ordinary processes and no completed flows under native AC. Starting with minimal commands separates the stages: loading the parent runtime, initializing Bash, executing the command and returning its results all affect an Agent's everyday tool calls. Next, we compare Microsoft MXC to see whether it handles these paths.
4 Can Git Bash run normally under Microsoft MXC?
Under native AC, Bash encounters access denied during initialization. Has Microsoft's own isolated execution solution already handled this problem? We use the official Microsoft eXecution Container (MXC) SDK 1.0.1 to repeat the same 18 basic Bash and interoperability cases. None passes; all 18 time out.
4.1 Minimal startup: the version query still does not return normally
Again, we begin with the simplest version query:
bash.exe --version This command prints its version and exits normally in an ordinary process. Under MXC, it produces no version output and is terminated by an external watchdog after about 15.3 seconds. An excerpt from the Git 2.56.1+1 group using the original runtime reads:
{ "id": "bash.version", "timed_out": true, "elapsed_seconds": 15.328, "problems": [ "timeout", "unexpected exit: 1", "missing stdout marker: GNU bash", "fixed Git Bash executable not observed" ] } We then test built-in commands, external tools, subshells, command substitution, pipes, redirection, background waiting, paths and environment variables, and interoperability with Python and Node.js. All 18 basic cases time out without completing their expected output, file and exit checks. From minimal startup to command combinations, this MXC round produces no passing result.
4.2 MSYS initialization: named-object access is still denied
We also investigated startup using the original runtime from the system's Git 2.51.0 installation. After preparing read and execute permissions for the Node directory, MXC creates the selected Bash process and its AC identity is observed. Bash nevertheless produces no version output, and stderr reports:
*** fatal error - NtCreateDirectoryObject(\BaseNamedObjects\msys-2.0S5-1888ae32e00d56aa): 0xC0000022 With Node read and execute permissions prepared, MXC can create an AC process, but MSYS is still denied access when creating its global named-object directory, at the same failure point as native AC. Process creation succeeds, while subsequent runtime initialization remains incomplete. Microsoft's public MXC issue and the upstream MSYS adaptation also describe similar problems involving named-object namespaces and access permissions. Experiment record · Public MXC issue · Upstream MSYS adaptation
From minimal startup to command combinations, this MXC round does not complete the 18 basic calls. Next, we examine how FinShield supports these execution paths, then give the command combinations already introduced to an Agent.
5 FinShield: completing execution of existing Git Bash scripts and Agent entries
5.1 The same version query now returns normally
FinShield developed a compatibility DLL for Git Bash to address MSYS runtime compatibility in AC, allowing existing Shell commands and scripts to execute normally.
The following command omits machine-specific absolute paths. The three variables point to the fixed FinShield executable, effective configuration and prepared Bash executable:
& $finshield run --yaml-path $policy --stdio pipe-inherit -- ` $bash --version The latest single retest returns normally. Its first stdout line is:
GNU bash, version 5.3.15(2)-release (x86_64-pc-cygwin) The exit code is 0, elapsed time is about 0.34 seconds, and the fixed Bash image has the expected AC identity. Together with the other completed, valid records, all 18 basic Bash and interoperability cases pass under FinShield, covering subshells, command substitution, pipes, redirection, background waiting, paths and calls across runtimes.
5.2 Combine the mechanisms, then give the script to an Agent
After individual commands work, we also need to verify that their combination completes a task. CodeBuddy and Hermes use the same fixed script. Its core is:
set -euo pipefail printf 'agent-pipeline-ok\n' | /usr/bin/tr a-z A-Z > agent-result.txt test "$(/usr/bin/cat agent-result.txt)" = AGENT-PIPELINE-OK "$MSYS_LAB_PYTHON" -c "print('PYTHON_FROM_AGENT_OK')" >> agent-result.txt pwd -W > agent-cwd.txt printf 'MSYS_AGENT_OK\n' >> agent-result.txt /usr/bin/cat agent-result.txt First, a pipeline changes text to uppercase and redirects it into a file. Second, the script reads the file back and checks its contents. Third, Bash starts the fixed Python executable and appends its output to the same file. Finally, it records the working directory, writes a completion marker and returns the results to the parent process. set -euo pipefail lets earlier execution errors affect the script's result. The script checks command combinations, file access, calls across runtimes and result collection together.
Both groups under FinShield produce the following output, with matching result-file contents:
AGENT-PIPELINE-OK PYTHON_FROM_AGENT_OK MSYS_AGENT_OK 5.3 CodeBuddy, WorkBuddy's execution core: a model invokes the Bash tool
CodeBuddy is WorkBuddy's execution core. This test uses CodeBuddy CLI 2.187.0 to have a model execute the fixed script through Bash. The prompt requires exactly one Bash call, with no command changes, software installation or attempted repair. Verification checks structured tool calls, tool results, an independent result file and the actual working directory.
Under MXC, the same task does not reach a Bash tool call: Node fails while loading the CodeBuddy CLI file entry with EPERM: operation not permitted, lstat 'D:\'. Under FinShield, the log records exactly one actual Bash tool call from the model, matching the fixed prompt. The tool result, organized by field, is:
Stdout: AGENT-PIPELINE-OK PYTHON_FROM_AGENT_OK MSYS_AGENT_OK Stderr: (empty) Exit Code: 0 is_error: false The CLI's final result is subtype=success. The independent file and working-directory checks pass, and the actual Bash process retains its AC identity. This verifies that the Agent calls Bash, Bash completes the script, and the results return to the Agent.
5.4 Hermes: using the released Shell implementation
The Hermes case uses LocalEnvironment._run_bash from public release v0.23.5, calling the released execution code directly. The core call below uses command to run the fixed script:
environment = LocalEnvironment( cwd=workspace, timeout=15, env={}, persistent=False, ) child = environment._run_bash(command, timeout=15) stdout, stderr = child.communicate(timeout=20) Hermes selects and starts the Shell, Bash runs the script, and the parent waits for output and exit. Under MXC, this entry times out after about 35.4 seconds without the expected markers or result file. Under FinShield, Hermes receives all three expected markers and exits with code 0. The file and working-directory checks pass, and the actual Bash process is observed with an AC identity. This case verifies the real Shell execution component without calling a model.
We also verify nine released component entries: AgentScope command execution and local MCP; Hermes terminal and long-lived processes; DSH Host, PowerShell and Bash; and OpenCode Shell and local MCP. All nine complete their specified execution, communication or shutdown flows under FinShield. The complete record lists each result and its verification scope.
6 Comparison: the Shell works while tools remain subject to permission controls
The 20 Git Bash cases, grouped by their actual uses, produce the following current results across four environments. Counts indicate completed flows, including output, files, exit status and the corresponding identity checks:
| Case scope | Ordinary process | Native AC | MXC 1.0.1 | FinShield 0.11.72 |
|---|---|---|---|---|
| Version query and built-in command | 2/2 | 0/2 | 0/2 | 2/2 |
| External commands, subshells, substitution, pipelines and background waiting | 5/5 | 0/5 | 0/5 | 5/5 |
| Redirection, paths with spaces and Chinese characters, working directory | 3/3 | 0/3 | 0/3 | 3/3 |
| Nested Bash and environment variables | 2/2 | 0/2 | 0/2 | 2/2 |
| Expected nonzero exit and conditional execution | 2/2 | 0/2 | 0/2 | 2/2 |
| Bash calls Python and Node.js | 2/2 | 0/2 | 0/2 | 2/2 |
| Python and Node.js call Bash | 2/2 | 0/2 | 0/2 | 2/2 |
| Actual CodeBuddy Bash tool task | 1/1 | 0/1 | 0/1 | 1/1 |
| Real Hermes Shell component | 1/1 | 0/1 | 0/1 | 1/1 |
| Total | 20/20 | 0/20 | 0/20 | 20/20 |
Native AC's direct Bash calls encounter access denied during MSYS initialization, while some parent-runtime entries fail earlier. The MXC group does not complete these 20 flows; timeouts and entry errors are listed separately in the records. FinShield completes all 20, and CodeBuddy and Hermes collect tool results through their existing execution paths.
We also verify Python and Node.js mechanisms, other Agent entries and channel diagnostics. The current valid records give:
| Verification scope | Ordinary process | Native AC | MXC 1.0.1 | FinShield 0.11.72 |
|---|---|---|---|---|
| Git Bash cases | 20/20 | 0/20 | 0/20 | 20/20 |
| Agent component entries | 9/9 | 0/9 | 0/9 | 9/9 |
| Python and Node.js mechanisms | 30/30 | 1/30 | 0/30 | 30/30 |
| Initialization diagnostics | 6/6 | 3/6 | 0/6 | 6/6 |
| Python channel checks | 4/4 | 2/4 | 0/4 | 4/4 |
| Total | 69/69 | 6/69 | 0/69 | 69/69 |
Under FinShield, an Agent can continue using Git Bash to execute commands, combine pipelines, access authorized files and call Python or Node.js. CodeBuddy and Hermes also complete their respective execution flows and collect the expected output and result files. All 69 checks in this verification have passing records: the existing tool chain works inside AC. Individual results and original errors are in the complete experiment record.
Tasks complete while program permissions remain controlled. The tested tools retain their AC identities and continue to operate under FinShield's permission restrictions. For example, permission to read a spreadsheet and generate a report should not also authorize recording audio, capturing the desktop, disrupting other windows, changing system settings, or reading and deleting other unauthorized files. Safety's comparison tests cover these risks and demonstrate FinShield's protection of privacy, desktop interactions, system resources and data. Privacy protection · Desktop protection · System protection · Data protection
原文:https://www.a8q9.cn/en/article/how-finshield-makes-git-bash-work-in-a-windows-sandbox-7255b7.html