{"record":{"id":"1ad3eef412958d9f","repo":"Unity-Technologies/ml-agents","slug":"the-folder-output-path-containing-the-generated","errorCode":null,"errorMessage":"The folder {output_path} containing the generated model could not be accessed. Please make sure the permissions are set correctly.","messagePattern":"The folder (.+?) containing the generated model could not be accessed\\. Please make sure the permissions are set correctly\\.","errorType":"exception","errorClass":"UnityEnvironmentException","httpStatus":null,"severity":"error","filePath":"ml-agents/mlagents/trainers/trainer_controller.py","lineNumber":89,"sourceCode":"    @timed\n    def _save_models(self):\n        \"\"\"\n        Saves current model to checkpoint folder.\n        \"\"\"\n        if self.rank is not None and self.rank != 0:\n            return\n\n        for brain_name in self.trainers.keys():\n            self.trainers[brain_name].save_model()\n        self.logger.debug(\"Saved Model\")\n\n    @staticmethod\n    def _create_output_path(output_path):\n        try:\n            if not os.path.exists(output_path):\n                os.makedirs(output_path)\n        except Exception:\n            raise UnityEnvironmentException(\n                f\"The folder {output_path} containing the \"\n                \"generated model could not be \"\n                \"accessed. Please make sure the \"\n                \"permissions are set correctly.\"\n            )\n\n    @timed\n    def _reset_env(self, env_manager: EnvManager) -> None:\n        \"\"\"Resets the environment.\n\n        Returns:\n            A Data structure corresponding to the initial reset state of the\n            environment.\n        \"\"\"\n        new_config = self.param_manager.get_current_samplers()\n        env_manager.reset(config=new_config)\n        # Register any new behavior ids that were generated on the reset.\n        self._register_new_behaviors(env_manager, env_manager.first_step_infos)","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/ml-agents/mlagents/trainers/trainer_controller.py#L71-L107","documentation":"TrainerController._create_output_path wraps os.makedirs in a try/except and re-raises UnityEnvironmentException when the model output folder cannot be created or accessed (permissions, invalid path, or a file existing at that path). Training cannot save models without a writable results directory, so it aborts early in start_learning.","triggerScenarios":"Running mlagents-learn with --results-dir or run_options.output_path pointing to a read-only directory, a nonexistent parent on a non-writable mount, a path that exists as a file, or a disk where os.makedirs throws (PermissionError/ OSError).","commonSituations":"Docker containers writing to a read-only volume; output path under / or another root-owned directory; results dir inside a OneDrive/synced folder locked by the OS; typo producing an invalid path.","solutions":["Choose a writable --results-dir, e.g. ./results or an absolute path under your home directory","Check/fix permissions with chmod/chown on the target directory","Ensure the output path is a directory, not an existing file","Create the parent directory manually and verify with a test write before launching training"],"exampleFix":"// before\nmlagents-learn config.yaml --results-dir=/root/locked/results\n// after\nmlagents-learn config.yaml --results-dir=./results","handlingStrategy":"validation","validationCode":"import os\noutput_path = \"./results\"\nif os.path.exists(output_path) and not os.path.isdir(output_path):\n    raise NotADirectoryError(output_path)\nos.makedirs(output_path, exist_ok=True)\nassert os.access(output_path, os.W_OK), f\"{output_path} is not writable\"","typeGuard":"def is_writable_dir(path) -> bool:\n    try:\n        os.makedirs(path, exist_ok=True)\n        return os.path.isdir(path) and os.access(path, os.W_OK)\n    except OSError:\n        return False","tryCatchPattern":"from mlagents_envs.exception import UnityEnvironmentException\ntry:\n    trainer_controller.start_learning()\nexcept UnityEnvironmentException as e:\n    logger.error(f\"Output path problem: {e}\")\n    raise SystemExit(\"Use a writable --results-dir\")","preventionTips":["Pass an explicit writable --results-dir relative to your project","Pre-create and chmod the results directory before long training runs","Avoid output paths on read-only mounts, network shares, or root-owned directories"],"tags":["python","mlagents","filesystem","permissions","output-path"],"backgroundTag":"output-directory-not-writable","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}