Solution was so simple I am ashamed I haven’t thought about it after going in circles for few hours.
Works as is, but I needed to move it on the ready callback into the config as discussed here: Can't access kirby() from the config file · Issue #1724 · getkirby/kirby · GitHub
So in the end I’ve got:
<?php
use Kirby\Filesystem\F;
return [
  ...
  'ready' => function($kirby) {
    $license_file = $kirby->root('license');
    $license = getenv('KIRBY_LICENSE');
    if ($license && !F::exists($license_file)) {
      F::write($license_file, $license);
    }
  }
];
Thanks again ![]()