Preface¶
When using the workspace-write sandbox of DeepSeek Harness (dsh) on Windows, before every controlled command execution the sandbox writes a write-permission grant into the DACL of the workspace root directory (AclWriteGrant.add → grantWrite). If any directory along the path chain lacks valid WRITE_DAC / WRITE_OWNER permissions, SetNamedSecurityInfoW fails with Win32 error 5 (ERROR_ACCESS_DENIED), manifesting as:
Error: SetNamedSecurityInfoW failed (Win32 5): grantWrite
After this, every controlled command on that workspace will fail before spawning, regardless of the specific shell command being run. Manually modifying the ACL or switching to a different directory can work around the issue, but doesn’t fit the pace of daily development. Below we introduce the community plugin dsh-grantwrite-patch (maintainer 0-v-0, category admin-security): when the above error is hit, it automatically repairs permissions and retries the command, allowing you to continue working seamlessly.
What Is This¶
dsh-grantwrite-patch is a Windows sandbox ACL repair plugin for dsh: it intercepts SetNamedSecurityInfoW Win32 5 failures in grantWrite scenarios, repairs permissions according to policy, then invisible-retries the original command. It only works on NTFS + Windows; on non-Windows platforms the plugin self-disables. Requires dsh >= 0.1.7-rc.1; the full diagnose script repair path requires dsh >= 0.2.0-rc.2. Only the workspace-write sandbox policy needs this plugin (read-only and danger-full-access do not).
How It Works¶
The plugin selects a strategy based on workspace size; three paths can be layered as needed without conflicting:
- Normal workspace: Intercepts the error in memory and retries, without modifying file permissions on disk.
- Large workspace: When the object count reaches a threshold (default 20,000), it proactively performs a full grant on the workspace once, avoiding the repeated cost of write grants on every DSH restart and making wait times for large directory trees more predictable.
- Fallback: When the above paths are unavailable, it runs a diagnose script once to repair permissions and retries; when the script is unavailable, it can fall back to
icaclsgrant (see Security Model).
The large/small determination uses a size probe; if the probe times out (default 10s), the workspace is treated as large; each workspace’s probe/decision is cached (default 1 hour).
Installation and Activation¶
Install via npm into a profile (similar to adding a dependency to a profile; once the bundle appears in dsh.profile.bundles, the cordis.patch.yml is loaded on next startup):
dsh plugin --profile web add dsh-grantwrite-patch
To update, simply run the same command again, e.g.:
dsh plugin --profile web add dsh-grantwrite-patch@latest
You can also manually merge the - insert: block from cordis.patch.yml in the repository into the host cordis.yml.
To install from source, you need to run pnpm build first (lib/ is not committed; the FFI preload comes from lib/preload.cjs in the package); steps are documented in the GitHub README, and the clone workflow is not covered here.
Configuration¶
The plugin is injected via cordis.patch.yml; typical fields are as follows (default values are per the README):
- insert:
id: grantwrite-patch
name: dsh-grantwrite-patch
config:
enable: true
mode: auto # auto | patch | repair
objectThreshold: 20000
probeTimeoutMs: 10000
probeCooldownMs: 3600000
repairTimeoutMs: 120000
maxRetries: 1
cooldownMs: 60000
appendDiagnostics: true
grantFallback: true
# scriptPath: <absolute path>
# outDir: <absolute path> # defaults to $DSH_HOME/grantwrite-patch
mode:autoautomatically selects patch / repair; you can also forcepatchorrepair.maxRetries: adjustable 0–3; repair failures will not be retried again, to avoid loops.grantFallback: whether to use bareicaclswhen the script is unavailable or fails; drive-letter roots will be rejected.
Security Model (Recommended Reading Before Installation)¶
The plugin runs in the dsh host process (not a restricted token), so modifying permissions is exactly what the sandbox’s restricted token cannot do; it does not elevate token privileges.
- patch path: Does not touch system ACLs, no persistent side effects; preserves
WRITE_RESTRICTED, capability-SID Allow ACE, world-SIDFILE_DELETE_CHILDDeny, etc.; only the Low-integrity label layer may be missing (when some hosts cannot apply labels at all, child processes run as Medium). - repair path: Scope is limited by the diagnose script’s
-AllowRoot, only modifying the target directory and its contents; rejects reparse points and managed application trees; does not delete Deny ACEs; backs up before changes and verifies after reading, with batch failures triggering rollback. - grantFallback:
icacls <root> /grant "<user>:(OI)(CI)F"; drive-letter roots (e.g.,D:\) are hard-rejected; does not modify inheritance policies or delete Deny; can be rolled back withicacls ... /remove:g. The script path is safer; the fallback only fills gaps.
Only matches SetNamedSecurityInfoW failures in the grantWrite context; other Win32 errors, command exit codes, EPERM, etc. are passed through unchanged.
Typical Usage¶
After installation and activation, no separate commands need to be written for grantWrite: simply run dsh controlled commands normally in a workspace that still uses workspace-write and has previously encountered Win32 5. The plugin repairs and retries on failure (default max 1 time, adjustable via maxRetries).
If the workspace has an extremely large number of files and startup or probing is slow, you can increase objectThreshold or probeTimeoutMs, or in large-workspace scenarios accept a one-time persistent repair to reduce the cost of subsequent grants (see README section “Large workspaces”).
Applicable Scenarios and Notes¶
Suitable for: Developers on Windows + NTFS who long-term use dsh workspace-write and whose workspace ACL chain is incomplete, causing grantWrite to be fully blocked.
Notes:
- The plugin runs with the current dsh process’s permissions; repair / icacls will modify workspace ACLs. Before installation, you should read the source code and the MIT license.
- The FFI core is adapted from masknull/dsh-acl-sandbox-patch.
- The community plugin directory SkillHub entry and GitHub are independent information sources, with no official affiliation to DeepSeek / High-Flyer; the DSH ecosystem emphasizes “everything is a plugin,” so choose as needed.
Conclusion¶
dsh-grantwrite-patch intercepts the Win32 5 error in the grantWrite phase of the Windows sandbox, selects patch / repair / script or icacls fallback based on scale, and restores command execution within a controlled number of retries. If you are stuck by SetNamedSecurityInfoW failed (Win32 5): grantWrite under workspace-write, you can first install via the npm command above, then adjust objectThreshold and security-related switches according to the README.
- Directory page: https://www.skillhub.cn/plugins/0-v-0/dsh-grantwrite-patch
- Repository: https://github.com/0-v-0/dsh-grantwrite-patch