The Rema in Siman 316 brings down the Halacha that it is prohibited to close a box or container in which there is a bug. Doing so constitutes the Melacha of Saad (trapping). This holds true even if the bug is not the type which is usually trapped, and the violation is only D’rabanan (rabbinic).
Interestingly, Maran does not bring this Halacha in Shulhan Aruch. This is especially puzzling since he does present this Halacha in his Bet Yosef, in the name of its source, the Sefer HaTerumah, and comments “Mi Yakel K’negdo?”-Who can be lenient against his ruling?
The Poskim explain why Maran didn’t bring this Halacha in Shulhan Aruch based on a general Halachic principle of Maran. In this case, the person closing the box does not intend to trap the bug; he just wants the box closed and the bug becomes trapped unintentionally, albeit inevitably. This is known as “Pesik Reshe D’lo Nicha Leh”-an action whose inevitable outcome is a Melacha, but that outcome was not the purpose of the action and the person has no interest or benefit from that outcome. Hacham Ovadia (Yabia Omer 4:15, Ohr Yisrael p. 92) holds that Maran’s position on such cases was to be lenient when the Melacha involved is M’drabanan (rabbinic). This could explain why Maran didn’t bring this prohibition, since the Melacha involved is only M’drabanan, as the case is referring to bugs that are not usually trapped. It goes without saying that if one is not sure whether there is even a bug in the box to begin with, there is no problem closing the box.
One may close a box containing a type of bug that is not usually trapped, if his intent is merely to seal the box and not to trap the bug.