{"record":{"id":"5b1b16ca7e52e12d","repo":"rohitg00/ai-engineering-from-scratch","slug":"os-system-denied","errorCode":null,"errorMessage":"os.system denied","messagePattern":"os\\.system denied","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"phases/19-capstone-projects/72-code-exec-metric/code/main.py","lineNumber":84,"sourceCode":"import 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\n    sys.stdout.write(json.dumps(status))\n    sys.exit(0)\nexcept Exception as exc:\n    status[\"exit_code\"] = \"error\"\n    status[\"detail\"] = \"compile error: %r\" % exc\n    sys.stdout.write(json.dumps(status))","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/19-capstone-projects/72-code-exec-metric/code/main.py#L66-L102","documentation":"The sandbox replaces os.system with a stub that always raises OSError, so candidate code attempting shell execution is blocked before any process spawns; this is a deliberate denial of the process-execution surface, triggered by the candidate calling os.system(cmd).","triggerScenarios":"Thrown at phases/19-capstone-projects/72-code-exec-metric/code/main.py:84 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Rewrite the candidate to accomplish the task in pure Python without shelling out","Catch OSError in the runner and score the attempt as a blocked/failed execution","Similarly avoid os.popen and subprocess since the module itself is denied"],"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"}