getgrav/grav · error · RuntimeException

Internal Error

Error message

Internal Error

What it means

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.

Source

Thrown at system/src/Grav/Console/Cli/SandboxCommand.php:94

        $this
            ->setName('sandbox')
            ->setDescription('Setup of a base Grav system in your webroot, good for development, playing around or starting fresh')
            ->addArgument(
                'destination',
                InputArgument::REQUIRED,
                'The destination directory to symlink into'
            )
            ->addOption(
                'symlink',
                's',
                InputOption::VALUE_NONE,
                'Symlink the base grav system'
            )
            ->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");

        $source = getcwd();
        if ($source === false) {
            throw new RuntimeException('Internal Error');
        }
        $this->source = $source;
    }

    /**
     * @return int
     */
    protected function serve(): int
    {
        $input = $this->getInput();

        $this->destination = $input->getArgument('destination');

        // Create Some core stuff if it doesn't exist
        $error = $this->createDirectories();
        if ($error) {
            return $error;
        }

View on GitHub (pinned to 6040efed04)

Solutions

  1. Run the command from a directory that definitely exists: `cd /path/to/grav && bin/grav sandbox <dest>`.
  2. If driven by a script, capture the repo path up front and explicitly cd into it immediately before invoking bin/grav so getcwd() resolves.
  3. Avoid deleting/renaming the directory the process is running from; operate on copies instead.

Example fix

# before (ghost cwd after the original dir was removed)
$ rm -rf /tmp/build && bin/grav sandbox /var/www/grav-dev   # getcwd() === false

# after
$ cd /srv/grav && bin/grav sandbox /var/www/grav-dev
Defensive patterns

Strategy: validation

Validate before calling

// guard before invoking bin/grav sandbox
$cwd = getcwd();
if ($cwd === false || !is_dir($cwd)) {
    chdir('/srv/grav'); // move to a known-good directory
}
// now exec('php bin/grav sandbox /var/www/grav-dev')

Try / catch

try {
    $command->run(...);
} catch (\RuntimeException $e) {
    if ($e->getMessage() === 'Internal Error') {
        // getcwd() failed: rerun from a valid directory
        chdir($repoRoot);
        passthru('php bin/grav sandbox ' . escapeshellarg($dest));
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of getgrav/grav@6040efed04 (2026-08-17). Data as JSON: /api/errors/ec3f9917343cbdfe. Report an issue: GitHub.