May a person spray insect repellent in his home on Shabbat?
One of thirty-nine categories of forbidden activity on Shabbat is "Ha'shochet," or slaughtering, which includes as well all cases of "Netilat Neshama" – taking the life of any living creature. Thus, it is forbidden to kill animals or insects on Shabbat.
Hence, Halacha would forbid spraying insect repellent in a manner that would invariably cause an insect to die. One may spray insect repellent only if he does so in the air – as opposed to directly on an insect – and he opens at least one window in the room to allow the insect to escape. The Chazon Ish (Rabbi Avraham Yeshaya Karelitz, Lithuania-Israel, 1879-1954) ruled more stringently, allowing one to spray under these conditions only if there is an ill patient in the home for whom the insects cause discomfort. Most other authorities, however, including Rabbi Moshe Halevi, in his work Menuchat Ahava (Helek 3, Perek 18:4), allow spraying into the air even if nobody in the home is ill, provided, as mentioned, that one leaves a window open, and the insects are causing discomfort to those in the room. (See Yabia Omer, Helek 3, O"H siman 20.)
One of the thirty-nine areas of forbidden activity on Shabbat, "Tzad," forbids trapping animals. On the level of Torah law, this prohibition applies only to creatures classified as "Be'mino Nitzod," meaning, species that people normally hunt. Trapping other animals is forbidden only by force of Rabbinic enactment.
The Rama (Rabbi Moshe Isserles, Poland, 1525-1572), in his glosses to the Shulchan Aruch (316:3; listen to audio for precise citation), writes that one must ensure not to close on Shabbat small receptacles that may contain flies, as he would then be trapping the flies on Shabbat. Therefore, if one sees his trashcan open on Shabbat, he should not place the cover on the can, given the likelihood that flies are inside the trash. The Mishna Berura (commentary to the Shulchan Aruch by Rabbi Yisrael Meir Kagan, the "Chafetz Chayim," Lithuania, 1839-1933) advises in such situation to cover the can but leave a small opening through which the flies could escape, and thereby avoid the prohibition of "Tzad." Furthermore, the Taz (commentary to the Shulchan Aruch by Rabbi David Halevi, Poland, 1586-1667) writes that one may close a trashcan after first sending away the flies he sees hovering around the top of the can. Since flies are not normally hunted, and thus trapping flies constitutes merely a Rabbinic prohibition, one need not search the trashcan to confirm the absence of flies before covering it. It suffices to send away the flies at the top of the can, and then place the cover.
The Shulchan Aruch rules (316:9) that one may trap an insect that could potentially harm a person, such as bees and yellow jacks. Since trapping these insects is forbidden only by force of Rabbinic enactment, we may be lenient in situations of potential harm. Therefore, on Sukkot, for example, if bees fly over or around the table in the Sukkah, it is permissible to trap them, even on Shabbat and Yom Tov.
Summary: Generally speaking, trapping animals and insects is forbidden on Shabbat, with the exception of potentially harmful insects, such as bees. One who wishes to cover his outdoor trashcan on Shabbat should either leave a small opening to allow flies inside the can to escape, or first shoo away any flies he sees on the top of the can. One may spray insect repellent on Shabbat into the air, but not directly on an insect, but he must leave at least one window open to allow the insects to escape, if the insects are causing discomfort to those in the room.