Question: May one walk in a place where there are ants on Shabbat?
Answer: One of the forbidden works on Shabbat is “killing a live creature”. For instance, if one slaughters a chicken on Shabbat, one has transgressed the Torah prohibition of killing on Shabbat.
It is therefore forbidden to kill any insect on Shabbat, such as an ant, for they too are living creatures. Indeed, the Sefer Issur Ve’Heter (Chapter 59) rules that one may not kill ants or other insects as one is walking on Shabbat. In places where such insects are found, one must be careful not to step on them. Several Acharonim, including Rabbeinu Yosef Haim in his Ben Ish Hai (Parashat Va’era), rule likewise.
Nevertheless, we must discuss this point. We have already explained in several places that performing a forbidden work which is not necessary for its own purpose is only forbidden on Shabbat as a result of a rabbinical enactment and is not forbidden according to the Torah. For instance, if one digs a ditch on Shabbat (which is a Torah prohibition of ploughing) but does not require the actual ditch and merely requires the dirt which he has dug out, one is not liable for a Torah transgression, for the Torah only prohibits performing a forbidden work on Shabbat which is necessary when one requires the actual result of the forbidden work. However, a forbidden work performed for another purpose only constitutes a rabbinical prohibition.
Based on this, Maran Rabbeinu Ovadia Yosef zt”l writes that since the prohibition here is only rabbinic (since one does not require the insects to be dead) and one is not intending to perform the forbidden work, this can be considered a situation where one performs an action whereby the forbidden work will certainly ensue; however, since one does not care that the forbidden work is being performed and the forbidden work is only rabbinic to begin with, this will be permissible. There is therefore no prohibition to walk on insects on Shabbat when one does not intend to kill them.
It is nevertheless preferable not walk on insects on Shabbat, as Maran zt”l writes in his Chazon Ovadia-Shabbat, Volume 5, page 124: “One may not step on insects, such as ants, on Shabbat even if one does not intend to kill them, for they will surely die when one steps on them. One should be cautious of this in places where they are present. However, if one has no other way to walk, this is permissible.”