{"record":{"id":"ec3f9917343cbdfe","repo":"getgrav/grav","slug":"internal-error-ec3f99","errorCode":null,"errorMessage":"Internal Error","messagePattern":"Internal Error","errorType":"console","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"system/src/Grav/Console/Cli/SandboxCommand.php","lineNumber":94,"sourceCode":"        $this\n            ->setName('sandbox')\n            ->setDescription('Setup of a base Grav system in your webroot, good for development, playing around or starting fresh')\n            ->addArgument(\n                'destination',\n                InputArgument::REQUIRED,\n                'The destination directory to symlink into'\n            )\n            ->addOption(\n                'symlink',\n                's',\n                InputOption::VALUE_NONE,\n                'Symlink the base grav system'\n            )\n            ->setHelp(\"The <info>sandbox</info> command help create a development environment that can optionally use symbolic links to link the core of grav to the git cloned repository.\\nGood for development, playing around or starting fresh\");\n\n        $source = getcwd();\n        if ($source === false) {\n            throw new RuntimeException('Internal Error');\n        }\n        $this->source = $source;\n    }\n\n    /**\n     * @return int\n     */\n    protected function serve(): int\n    {\n        $input = $this->getInput();\n\n        $this->destination = $input->getArgument('destination');\n\n        // Create Some core stuff if it doesn't exist\n        $error = $this->createDirectories();\n        if ($error) {\n            return $error;\n        }","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/getgrav/grav/blob/6040efed04efa69b8209448ed81308e7c24147c2/system/src/Grav/Console/Cli/SandboxCommand.php#L76-L112","documentation":"The sandbox command (bin/grav sandbox <destination>) captures the current working directory as the source of the Grav checkout to link from. PHP's getcwd() returns false when the process's cwd no longer exists (or cannot be determined), and the command refuses to continue with this RuntimeException instead of proceeding with a bogus source path.","triggerScenarios":"Running `bin/grav sandbox ...` from a directory that was deleted or renamed while the shell/process was still in it; running under an environment (some chroots, containers, cron wrappers) where the cwd handle is invalid; scripts that chdir() into a temp dir, remove it, then shell out to bin/grav.","commonSituations":"CI job that clones into a temp folder, cds into it, cleans it up, and then invokes bin/grav from the stale cwd; deploy scripts renaming the release directory mid-run; interactive shell left in a removed directory (on Linux the shell keeps a ghost cwd).","solutions":["Run the command from a directory that definitely exists: `cd /path/to/grav && bin/grav sandbox <dest>`.","If driven by a script, capture the repo path up front and explicitly cd into it immediately before invoking bin/grav so getcwd() resolves.","Avoid deleting/renaming the directory the process is running from; operate on copies instead."],"exampleFix":"# before (ghost cwd after the original dir was removed)\n$ rm -rf /tmp/build && bin/grav sandbox /var/www/grav-dev   # getcwd() === false\n\n# after\n$ cd /srv/grav && bin/grav sandbox /var/www/grav-dev","handlingStrategy":"validation","validationCode":"// guard before invoking bin/grav sandbox\n$cwd = getcwd();\nif ($cwd === false || !is_dir($cwd)) {\n    chdir('/srv/grav'); // move to a known-good directory\n}\n// now exec('php bin/grav sandbox /var/www/grav-dev')","typeGuard":null,"tryCatchPattern":"try {\n    $command->run(...);\n} catch (\\RuntimeException $e) {\n    if ($e->getMessage() === 'Internal Error') {\n        // getcwd() failed: rerun from a valid directory\n        chdir($repoRoot);\n        passthru('php bin/grav sandbox ' . escapeshellarg($dest));\n    }\n}","preventionTips":["Never delete or rename the directory a long-running process (or its shell) uses as cwd.","In CI/deploy scripts, cd into an absolute path immediately before invoking bin/grav.","Treat getcwd() === false as an environment bug: fix the harness, not the command."],"tags":["grav","cli","filesystem","cwd","sandbox"],"backgroundTag":"invalid-working-directory","analyzedSha":"6040efed04efa69b8209448ed81308e7c24147c2","analyzedAt":"2026-08-17T05:07:31.593Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}