MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / test_policy_applies_to_exec_commands

Function test_policy_applies_to_exec_commands

e2e/python/test_sandbox_policy.py:361–386  ·  view source on GitHub ↗
(
    sandbox: Callable[..., Sandbox],
)

Source from the content-addressed store, hash-verified

359
360
361def test_policy_applies_to_exec_commands(
362 sandbox: Callable[..., Sandbox],
363) -> None:
364 def current_user() -> str:
365 import os
366 import pwd
367
368 return pwd.getpwuid(os.getuid()).pw_name
369
370 def write_allowed_files() -> str:
371 from pathlib import Path
372
373 Path("/sandbox/allowed.txt").write_text("ok")
374 Path("/tmp/allowed.txt").write_text("ok")
375 return "ok"
376
377 spec = datamodel_pb2.SandboxSpec(policy=_policy_for_python_proxy_tests())
378
379 with sandbox(spec=spec, delete_on_exit=True) as policy_sandbox:
380 user_result = policy_sandbox.exec_python(current_user)
381 assert user_result.exit_code == 0, user_result.stderr
382 assert user_result.stdout.strip() == "sandbox"
383
384 file_result = policy_sandbox.exec_python(write_allowed_files)
385 assert file_result.exit_code == 0, file_result.stderr
386 assert file_result.stdout.strip() == "ok"
387
388
389def test_policy_blocks_unauthorized_proxy_connect(

Callers

nothing calls this directly

Calls 3

sandboxFunction · 0.70
exec_pythonMethod · 0.45

Tested by

no test coverage detected