MCPcopy Create free account
hub / github.com/Louisym/MiniCC / demo_sandbox_decision_tree

Function demo_sandbox_decision_tree

tutorials/14_bash_engine_deep_dive.py:776–815  ·  view source on GitHub ↗

展示沙箱决策过程

()

Source from the content-addressed store, hash-verified

774
775
776def demo_sandbox_decision_tree():
777 """展示沙箱决策过程"""
778 print("\n" + "=" * 60)
779 print("沙箱决策树演示")
780 print("=" * 60)
781
782 cwd = Path.cwd()
783
784 scenarios = [
785 ("默认配置", SandboxConfig(), None),
786 ("用户关闭沙箱", SandboxConfig(enabled=False), None),
787 ("模型请求禁用沙箱", SandboxConfig(), True),
788 ("网络隔离", SandboxConfig(network_isolation=True), None),
789 ("白名单模式", SandboxConfig(
790 filesystem_mode=FilesystemIsolationMode.ALLOW_LIST,
791 allowed_mounts=["logs", "/var/data"],
792 ), None),
793 ]
794
795 for name, config, disable_override in scenarios:
796 request = resolve_request(
797 config,
798 enabled_override=(not disable_override
799 if disable_override is not None else None),
800 )
801 status = resolve_sandbox_status(request, cwd)
802
803 print(f"\n--- {name} ---")
804 print(f" 请求: enabled={request.enabled}, "
805 f"ns={request.namespace_restrictions}, "
806 f"net={request.network_isolation}, "
807 f"fs={request.filesystem_mode.value}")
808 print(f" 结果: active={status.active}, "
809 f"ns_active={status.namespace_active}, "
810 f"net_active={status.network_active}, "
811 f"fs_active={status.filesystem_active}")
812 if status.fallback_reason:
813 print(f" 降级: {status.fallback_reason}")
814 if status.in_container:
815 print(f" 容器: {status.container_markers}")
816
817
818def demo_container_detection():

Callers 1

Calls 3

resolve_requestFunction · 0.85
SandboxConfigClass · 0.70
resolve_sandbox_statusFunction · 0.70

Tested by

no test coverage detected