MCPcopy Create free account
hub / github.com/vercel/examples / select_safe_cwd

Function select_safe_cwd

python/vibe-coding-ide/backend/src/sandbox/command.py:7–26  ·  view source on GitHub ↗

Resolve a safe working directory under the sandbox's base cwd. Absolute paths outside the sandbox root are ignored. Relative paths are resolved under the base cwd. Falls back to base cwd on errors.

(requested_cwd: str | None, base_cwd: str)

Source from the content-addressed store, hash-verified

5
6
7def select_safe_cwd(requested_cwd: str | None, base_cwd: str) -> str:
8 """Resolve a safe working directory under the sandbox's base cwd.
9
10 Absolute paths outside the sandbox root are ignored. Relative paths are
11 resolved under the base cwd. Falls back to base cwd on errors.
12 """
13 safe_cwd = base_cwd
14 try:
15 if requested_cwd:
16 if requested_cwd.startswith("/"):
17 if (
18 requested_cwd.startswith(base_cwd + "/")
19 or requested_cwd == base_cwd
20 ):
21 safe_cwd = requested_cwd
22 else:
23 safe_cwd = f"{base_cwd}/{requested_cwd}".rstrip("/")
24 except Exception:
25 safe_cwd = base_cwd
26 return safe_cwd
27
28
29def detect_language_usage(command: str) -> tuple[bool, bool, bool]:

Callers 1

sandbox_runFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected