Saving Virtual Layer to temporary layer

You are absolutely right that Virtual Layers are useful only to a certain extend.

What you can do is to create a Virtual Layer by means of PyQGIS and saving it as a GeoPackage or working with it as a temporary vlayer.

vlayer = QgsVectorLayer("?query=SELECT * FROM 'your_layer'", "vlayer", "virtual")

writer = QgsVectorFileWriter.writeAsVectorFormat(vlayer, r"C:/.../output.gpkg", "GeoPackage")

if writer[0] == QgsVectorFileWriter.NoError:
    print("success!")
else:
    print("error")

References:

  • Creating new Virtual Layer programmatically in QGIS?
  • Virtual layers for QGIS | Known limitations / Future developments
  • QGIS-Developer | QGIS virtual layer incredibly slow