Is there a way to setup and install local virtual machine programmatically (i.e. JavaScript) and run an application inside it?

The idea is that I have an application needs some specific configurations on Ubuntu but I need it to be installed on Windows and Mac OS. So I’m thinking about an Ubuntu VM that I can setup and run the application inside it and it will be enabled to be hosted on any OS like below image.

enter image description here