MCPcopy Create free account
hub / github.com/Noumena-Network/code / getSimpleSandboxSection

Function getSimpleSandboxSection

src/tools/BashTool/prompt.ts:173–274  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

171}
172
173function getSimpleSandboxSection(): string {
174 if (!SandboxManager.isSandboxingEnabled()) {
175 return ''
176 }
177
178 const fsReadConfig = SandboxManager.getFsReadConfig()
179 const fsWriteConfig = SandboxManager.getFsWriteConfig()
180 const networkRestrictionConfig = SandboxManager.getNetworkRestrictionConfig()
181 const allowUnixSockets = SandboxManager.getAllowUnixSockets()
182 const ignoreViolations = SandboxManager.getIgnoreViolations()
183 const allowUnsandboxedCommands =
184 SandboxManager.areUnsandboxedCommandsAllowed()
185
186 // Replace the per-UID temp dir literal (e.g. /private/tmp/claude-1001/) with
187 // "$TMPDIR" so the prompt is identical across users — avoids busting the
188 // cross-user global prompt cache. The sandbox already sets $TMPDIR at runtime.
189 const claudeTempDir = getNcodeTempDir()
190 const normalizeAllowOnly = (paths: string[]): string[] =>
191 [...new Set(paths)].map(p => (p === claudeTempDir ? '$TMPDIR' : p))
192
193 const filesystemConfig = {
194 read: {
195 denyOnly: dedup(fsReadConfig.denyOnly),
196 ...(fsReadConfig.allowWithinDeny && {
197 allowWithinDeny: dedup(fsReadConfig.allowWithinDeny),
198 }),
199 },
200 write: {
201 allowOnly: normalizeAllowOnly(fsWriteConfig.allowOnly),
202 denyWithinAllow: dedup(fsWriteConfig.denyWithinAllow),
203 },
204 }
205
206 const networkConfig = {
207 ...(networkRestrictionConfig?.allowedHosts && {
208 allowedHosts: dedup(networkRestrictionConfig.allowedHosts),
209 }),
210 ...(networkRestrictionConfig?.deniedHosts && {
211 deniedHosts: dedup(networkRestrictionConfig.deniedHosts),
212 }),
213 ...(allowUnixSockets && { allowUnixSockets: dedup(allowUnixSockets) }),
214 }
215
216 const restrictionsLines = []
217 if (Object.keys(filesystemConfig).length > 0) {
218 restrictionsLines.push(`Filesystem: ${jsonStringify(filesystemConfig)}`)
219 }
220 if (Object.keys(networkConfig).length > 0) {
221 restrictionsLines.push(`Network: ${jsonStringify(networkConfig)}`)
222 }
223 if (ignoreViolations) {
224 restrictionsLines.push(
225 `Ignored violations: ${jsonStringify(ignoreViolations)}`,
226 )
227 }
228
229 const sandboxOverrideItems: Array<string | string[]> =
230 allowUnsandboxedCommands

Callers 1

getSimplePromptFunction · 0.85

Calls 12

dedupFunction · 0.85
normalizeAllowOnlyFunction · 0.85
jsonStringifyFunction · 0.85
prependBulletsFunction · 0.85
isSandboxingEnabledMethod · 0.80
getFsReadConfigMethod · 0.80
getFsWriteConfigMethod · 0.80
getAllowUnixSocketsMethod · 0.80
getIgnoreViolationsMethod · 0.80
keysMethod · 0.80

Tested by

no test coverage detected