The earliest time you can execute code is at CRT initialization, which is basically the initialization of top-level static variables. It happens even before Main or DllMain.
In a monolithic (shipping) build you have a single executable so the CRT init happens (including project code) before Main. None of the engine framework will be available at this point though.
You can bind the FCoreDelegate::OnInit delegate to get a callback when the engine is initializing, and you may have access to a few more things (don’t know the specifics).
You can declare your own Game module subclass and override StartupModule, to execute code when your module is loaded (meaning all engine modules and project dependent modules are already loaded)
You can bind the FCoreDelegate::OnPostEngineInit delegate to get a callback slightly after (don’t know the specifics, probably all modules are loaded)
In modular build (editor, built with DLLs) your project’s DLL is loaded much later (at the time StartupModule is called) and there is no way to execute code beforehand. Also afaik you cannot use the OnInit delegate since your game module is loaded after its trigger.
If you want to execute code earlier in a modular build, you might have to make an engine-level plugin.
When you create a C++ project, the bootstrapper automatically creates the ProjectName.cpp file that registers your game module. You can start here, and see what fits you best.