The root script for Magento 2 is the speediest way to print something, collect data, or check something using the Object Manager.
For example, if you want to get the order details and print them, you can create a root script Magento 2.
Alternatively, you could want to use the root script, such as test.php, to determine where a Magento 2 store is located within the hosting environment.
As a result, the post demonstrates how to create a custom Magento 2 root script, which can save a developer time.
Here you can find steps to create a root script in Magento 2,
https://meetanshi.com/blog/create-root-script-in-magento-2/