Danger to life overrides Shabbat. Therefore, animals likely to endanger human life may be killed even on Shabbat, like poisonous snakes and scorpions. Even if one is unsure whether a particular animal is poisonous, he may kill it. Similarly, a dangerous dog or rabid animal may be killed.
It is prohibited on Shabbat to kill animals whose bites hurt a great deal but are not life-threatening. This applies to snakes and scorpions that are definitely not poisonous. It is only forbidden to kill them the way one would kill them during the week, so one may kill them in the course of walking; one walks in their direction and in the course of walking steps on them and kills them. The reason for this dispensation is that killing an animal in a destructive manner, when one does not have any use for the cadaver, is only prohibited rabbinically. Thus, in order to avoid great suffering, the Sages permitted killing such animals in the course of walking. However, it is prohibited to kill them directly, out of concern that people will conclude that one may kill animals even when there is no concern that they will cause harm. If such animals are chasing a person, they may be killed even without a shinui.
Even if they are not chasing anyone, a receptacle may be placed over them in order to neutralize the threat. This does not need to be done with a shinui, because the person’s goal is not to trap them, only to prevent them from stinging or biting (SA 316:7; MB ad loc. 27).
Animals whose stings are not so painful, such as mosquitoes and fleas, may not be killed in any manner on Shabbat. If the mosquito or flea is clinging to one’s skin and cannot be removed without being grabbed, the Sages permitted grabbing it in order to remove it. This is on condition that he not kill it or even squeeze it, which might kill it. Even though grabbing an animal without intending to use it is rabbinically prohibited, the Sages were lenient here since the goal is to avoid suffering (SA 316:9). If one wishes to grab a flea and remove it from under his clothing rather than from his skin need not be dissuaded from doing so (MB 316:37; SHT ad loc. 63).
If there are mosquitoes or other pests in a room, one may spray insecticide to repel them as long as he does not spray the bugs directly and leaves open a window through which they can escape. This way he will not necessarily kill any of them. However, one may not spray them directly or to spray in a place where they have no means of escape, because then he will definitely kill them and transgress a prohibition (Yabi’a Omer 3:20; see SSK 25:6).
One may apply liquid mosquito repellent on Shabbat, but not an ointment (see above, 14:5).
One may place tablets into a plug-in device that contains a heating element that causes the tablets to heat up and release a mosquito-repellent vapor. It is proper to place the tablets at a short distance from the heating element so that they do not reach the temperature of yad soledet bo, which might present a problem of Bishul (Ha-ĥashmal Ba-halakha vol. 2, p. 364; above 10:4). However, if one is uncertain whether the tablets will reach yad soledet bo, he may place them.