There is a plugin that does what you need: [Mask][1]

Or since 3.22 (no sure the version), there is also a new type of symbology called « [inverted polygon render][2] », with which you can do a mask outside your polygon

(Get there via: right click on layer name -> `Properties...` -> `Symbology` -> select `Inverted Polygons` from dropdown menu on top.)


  [1]: https://plugins.qgis.org/plugins/mask/
  [2]: https://docs.qgis.org/3.22/en/docs/user_manual/working_with_vector/vector_properties.html?highlight=symbology#inverted-polygon-renderer