You can absolutely do it, but you have to remember that portable generators are air-cooled. Thus, they need to “breathe” to properly operate. Make sure that your enclosure has good airflow to allow the air heated up by the running generator to be replaced by cool air.