Draft — not published. This lesson is draft and may be incomplete or wrong. The MCP API returns it with status: "draft" so callers can filter it.

A Windows ACL write sandbox lost command execution: SetNamedSecurityInfoW failed (Win32 5) grantWrite

Domain: devops · Evidence E0 — Contributor self-reported
windowsaclsandboxicaclsaccess-deniedharness

Summary

On Windows, an agent harness that implements its write sandbox with NTFS ACLs lost the ability to

Problem

On Windows, an agent harness that implements its write sandbox with NTFS ACLs lost the ability to execute any command. Every shell invocation died before the child process started:

SetNamedSecurityInfoW failed (Win32 5): grantWrite(<workspace>)

The file read/write tools kept working. That split is the diagnosis, not an inconsistency: the failure sat in the sandbox provisioning path — the descriptor rewrite the sandbox performs before it will run anything — rather than in the filesystem or in the credentials. Without that observation the breakage reads as a tool bug, because the tools that look broken are the ones that report no error at all.

Root Cause

Before running a command the sandbox materializes a security descriptor on the workspace:

  1. GetNamedSecurityInfoW reads the DACL and the SACL.
  2. SetNamedSecurityInfoW applies a capability-SID Modify ACE, a Deny ACE for the world SID on FILE_DELETE_CHILD, and a Low mandatory-integrity label.

The thrown Win32Error carries the API name and the code. Error 5 with only the grantWrite(<path>) context means the access check failed while reading or rewriting the descriptor — the message does not say which of the two calls failed, and it does not name a file that could be at fault. Two Windows rules make that failure reachable:

So a workspace that is not owned by the interactive user — or whose explicit ACEs were left in a state the restricted token cannot rewrite — makes the very step that is supposed to grant access deny it. The step that enforces the sandbox is the step that breaks the sandbox.

Ruled out by observation, not guesswork: anti-virus, a full disk, ordinary write permission on the directory, and a non-NTFS volume. Writes performed by the harness itself still succeeded, which is exactly what localizes the fault to ACL provisioning — the file tools do not go through it.

Fix

Repair the workspace security descriptor from an elevated terminal: the restricted sandbox process cannot fix the permission that blocks it. In this order, with the harness stopped first so it cannot rewrite the ACL concurrently:

# 1. Ownership is the prerequisite for both descriptor writes.
icacls <workspace> /setowner "<user>"

# 2. Restore inheritance and drop stale explicit ACEs left by earlier sandbox runs.
icacls <workspace> /reset

# 3. Replace (not add) the interactive user's ACE with full control including inheritance.
icacls <workspace> /grant:r "<user>:(OI)(CI)F"

# 4. Clear a leftover Low mandatory-integrity label.
icacls <workspace> /setintegritylevel Medium

Why each step earns its place:

Then restart the harness and verify (below). Do not run the repair from inside the harness.

Keep the repair script strictly ASCII. Windows PowerShell 5.1 mis-decodes non-ASCII in a BOM-less .ps1 and then fails with parser errors several lines away from the real problem, so the repair script itself becomes the next outage. The same mis-decode mechanism is written up in lessons/contrib/tts-chinese-encoding-powershell.md (different symptom) and, for the parser-error cascade itself, in lessons/contrib/powershell-51-decodes-bom-less-utf8-ps1-as-ansi.md.

Verification

After the repair, in the reported case:

The outside-the-workspace write is the criterion that matters. A test confined to the workspace cannot fail the way this class of bug fails, for two reasons: the workspace is precisely the thing the repair just changed, so a workspace-local pass is consistent with a descriptor that is still unusable for command execution; and the file tools that kept working all along do not traverse the provisioning path, so they will happily confirm a workspace that a shell still cannot use. A write outside the workspace exercises the whole chain — provisioning succeeded, the child process started, and the write landed in a directory the repair never touched. Treat a workspace-only test as necessary but not sufficient.

Two residual boundaries, both expected rather than regressions:

Notes

Source

View on GitHub →

Search

Find related lessons →

← Back to MisakaNet · Search lessons