Building fails on remote with error Missing SConscript 'build.py'

I installed the pio remote agent successful on a raspberry.
But remote uploading a firmware fails while building on the remote:

warning: Calling missing SConscript without error is deprecated.
Transition by adding must_exist=False to SConscript calls.
Missing SConscript 'build.py'
File "/home/pi/.platformio/penv/lib/python3.9/site-packages/platformio/builder/main.py", line 186, in <module>
*** [upload] Source `.pio/build/usb/firmware.bin' not found, needed by target `upload'.
========================== [FAILED] Took 4.15 seconds ==========================

I am using a custom build.py referenced in platformio.ini:
extra_scripts = pre:build.py

The build.py resides in the root directory of the project.

I solved this by moving the build.py script from root to /src folder of project. This way it works.