{"record":{"id":"828c3b85b09879dd","repo":"rohitg00/ai-engineering-from-scratch","slug":"denied-module-s","errorCode":null,"errorMessage":"denied module: %s","messagePattern":"denied module: (.+?)","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"phases/19-capstone-projects/72-code-exec-metric/code/main.py","lineNumber":78,"sourceCode":"            \"per_assertion\": list(self.per_assertion),\n        }\n\n\nRUNNER_TEMPLATE = r\"\"\"\nimport json, sys, traceback\nimport builtins as _builtins\n\n_DENIED_MODULES = {\n    'subprocess', 'socket', 'shutil', 'requests', 'urllib',\n    'urllib.request', 'urllib.error', 'urllib.parse', 'ctypes',\n    'http.client', 'asyncio.subprocess',\n}\n\n_real_import = _builtins.__import__\ndef _guarded_import(name, *args, **kwargs):\n    base = name.split('.')[0]\n    if name in _DENIED_MODULES or base in _DENIED_MODULES:\n        raise ImportError(\"denied module: %s\" % name)\n    return _real_import(name, *args, **kwargs)\n_builtins.__import__ = _guarded_import\n\nimport os as _os\ndef _denied_system(_cmd):\n    raise OSError(\"os.system denied\")\n_os.system = _denied_system\n\nCODE = __PLACEHOLDER_CODE__\nASSERTIONS = __PLACEHOLDER_ASSERTIONS__\n\nns = {}\nstatus = {\"exit_code\": \"pass\", \"results\": [], \"detail\": \"\"}\ntry:\n    compiled = compile(CODE, \"<candidate>\", \"exec\")\nexcept SyntaxError as exc:\n    status[\"exit_code\"] = \"syntax_error\"\n    status[\"detail\"] = \"SyntaxError: %s\" % exc","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/19-capstone-projects/72-code-exec-metric/code/main.py#L60-L96","documentation":"The sandboxed runner replaces builtins.__import__ so candidate code cannot import dangerous modules (subprocess, socket, shutil, requests, urllib, ctypes, http.client, and their submodules); this ImportError is raised inside the candidate's own import statement when it requests a blocked module or any submodule whose root name is blocked.","triggerScenarios":"Thrown at phases/19-capstone-projects/72-code-exec-metric/code/main.py:78 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Rewrite the candidate solution to use only allowed stdlib modules (e.g. use math and collections instead of subprocess)","Treat this failure as a scored security violation in the eval, not as a crash: catch ImportError and mark the assertion set as failed","Extend _DENIED_MODULES deliberately if the harness should block more surfaces"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}