HKUDS/Vibe-Trading · error · ValueError

UNC paths are not allowed: {p!r}

Error message

UNC paths are not allowed: {p!r}

What it means

_rejects_unc rejects any path string starting with a UNC share prefix (backslash or forward-slash double prefix) before any resolution occurs, because UNC shares bypass workspace containment. Used by safe_path, resolve_safe_path, allowed-write-root and import-root helpers.

Source

Thrown at agent/src/tools/path_utils.py:43

_ALLOWED_FILE_ROOTS_ENV = "VIBE_TRADING_ALLOWED_FILE_ROOTS"
_ALLOWED_RUN_ROOTS_ENV = "VIBE_TRADING_ALLOWED_RUN_ROOTS"

# MCP clients spawn the server themselves, so a shell export never reaches it.
_ENV_SCOPE_HINT = (
    "Under an MCP client, set it in that client's server env block — "
    "exporting it in a shell does not reach the spawned server."
)


def _describe_roots(roots: list[Path]) -> str:
    """Render allowed roots as an indented list for a rejection message."""
    return "Allowed roots:\n" + "\n".join(f"  - {root}" for root in roots)


def _rejects_unc(p: str) -> None:
    """Raise ValueError if `p` starts with a UNC share prefix."""
    if p.startswith("\\\\") or p.startswith("//"):
        raise ValueError(f"UNC paths are not allowed: {p!r}")


def safe_path(p: str, workdir: Path) -> Path:
    """Resolve `p` under `workdir` and ensure it stays inside.

    Args:
        p: User-supplied path (relative or absolute).  ``~`` expansion is
            supported so callers can pass home-relative paths.
        workdir: Workspace root. `p` must resolve to a location inside.

    Returns:
        Absolute resolved path inside `workdir`.

    Raises:
        ValueError: If `p` uses a UNC share, or its resolved form escapes
            `workdir`. Callers surface this back to the LLM as a tool error.
    """
    _rejects_unc(p)

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Copy or symlink the data into a local allowed directory and reference that path
  2. Normalize the path (strip the leading double separator) if it was a plain local path mangled by escaping
  3. Configure allowed roots with local absolute paths only

Example fix

// before
file_path = "\\\\fileserver\\data\\prices.csv"
// after
file_path = "/workspace/data/prices.csv"
Defensive patterns

Strategy: validation

Validate before calling

def is_unc(p: str) -> bool:
    return p.startswith("\\\\") or p.startswith("//")

if is_unc(file_path):
    raise ArgumentError("copy the file into a local allowed directory")

Type guard

def is_local_path(p: str) -> bool:
    return not (p.startswith("\\\\") or p.startswith("//"))

Try / catch

try:
    safe = safe_path(file_path, workdir)
except ValueError as e:
    if "UNC" in str(e):
        file_path = copy_to_workspace(file_path); safe = safe_path(file_path, workdir)

Prevention

When it happens

Trigger: Passing '\\\\server\\share\\file.csv' or '//server/share/file.csv' as file_path, run_dir, or as a configured root (file roots env var).

Common situations: Windows network shares, WSL/docker mounts mapped to UNC, or mis-escaped backslashes producing a leading double slash.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/efe2b4f1c3d04ced. Report an issue: GitHub.