Yes, virtual machines are legal. They are mainly used to run and test multiple operating systems under single hardware. It’s also used to run emulators.