The Mishna Berura (Rav Yisrael Kagan of Radin, 1839-1933) in Siman 316 rules that one may not set up a mousetrap on Shabbat. Even though he is not directly catching the mouse with his own hands, it is still a rabbinic violation of the Melacha of Saad (trapping). The Ben Ish Hai (Rav Yosef Haim of Baghdad, 1833-1909)in Parashat Vaera (Halacha 7) concurs with this position and rules that therefore, a mousetrap is Mukse as a Keli She’m’lachto L’isur (a utensil designated for a prohibited function).
Hacham Ovadia takes a different approach to the question of mousetraps. He argues that setting up the trap is permitted on Shabbat, since the trapping is only done by Gerama (indirectly), which is permitted by Maran. Accordingly, a mousetrap is not Mukse, but once a mouse is caught, the mouse is Mukse.
Hacham Ovadia also permits spraying bug spray in a room, on condition that it is not sprayed directly on the bugs and a window is left open to give them a chance to escape. Even though that will cause the bugs to die, it is permitted since it is not a direct and inevitable act of killing on Shabbat. He also allows hanging flypaper on Shabbat.
It is permitted to set up a mousetrap on Shabbat. It is also permitted to spray bug spray in a room with an open window, as long as it is not sprayed directly on the bugs. It is permitted to hang flypaper on Shabbat.