With regards to just Windows.
I have not tried this yet as I just learned of Windows Sandbox.
Windows Sandbox has the ability to use a configuration file and the configuration file has a logon command.
Since what you seek is so common among developers at the end of the configuration file page they even give an example that installs Visual Studio Code. As for persisting work once the Sandbox is ended, there are mapped folders.
If all of this makes you think of Docker, WSL or OCI then you are thinking the same as me.
If you try this, I would be interested in what you discover.
I plan to try this but put the configuration file and map the folders to a USB flash drive and just use different USB flash drives for different projects, think
plug, boot and play. Now if only I could get it so that plugging in a USB flash drive booted a sandbox and saved on unplugging it would be nice. I know, that is what cloud computing does, but I am cheap.
Out of curiosity I wondered if Mac OS had similar, I found App Sandbox. Since I don’t have a Mac I have no way of doing anything practical to learn about App Sandbox.