When Noah came out of the ark after the Flood, G‑d re-articulated the seven Noahide commandments to him. Included in this is the prohibition of tearing the flesh off a living animal, which generalizes to causing unnecessary pain to animals.
Regarding killing animals, it is mentioned in the Zohar (2:68b) that no creature was created purposelessly.
It is [therefore] forbidden to kill purposelessly.
As the sages state:
"All that the Holy One, blessed be He, created, He created only for His honor, as it is written, All that is called in My Name and for My honor, I created it, I formed it, I even made it." (Avot 6:11; Isaiah 43:7)
We will see now how the Arizal took this statement to extreme conclusions, conducting himself with extreme piety in this matter.
My teacher [the Arizal] was very careful not to kill any bug, even the smallest and lowliest, such as fleas, lice, flies, and the like, even when they bit him.
We know what the sages say, commenting on the verse, "His enemies will also make peace with him," (Proverbs 16:7) that some say this refers to the dog and others say this refers to the snake, and still others say this refers to the flea. (Y. Terumah 8:3)
This idea is the answer of Rabbi Elazar to Rabbi Chizkiyah recorded in the Zohar (2:68b), where the mystical meaning of the verse "Will the snake bite without whispering?" (Eccl. 10:11) is explained.
Rabbi Elazar and Rabbi Chizkiyah were walking and came across a snake. Rabbi Chizkiyah was about to kill it, but Rabbi Elazar told him not to. When Rabbi Chizkiyah protested, saying that it is a dangerous creature, Rabbi Elazar quoted the above verse, interpreting it to mean that a snake only bites a person if G‑d "whispers" to him to do so. G‑d created snakes in order to kill certain people and thereby prevent them from doing some evil.
To be sure, we should not kill any creature unnecessarily, but refraining from killing animals that pose a threat to human life (or communicate diseases) contradicts the requirements of Jewish law, and it is doubtful whether any Torah authority would permit this. Indeed, it is permitted to kill harmful snakes on the Sabbath, when killing is otherwise altogether prohibited.
The Arizal, we may presume, did not have to worry about leaving snakes alive because he did not have to fear being stuck down by one to prevent him from sinning. On the other hand, we see that he was bitten by insects and bugs. The question is how the Arizal could refrain from killing snakes and the like and allow them to pose a threat to others' lives. Perhaps the Arizal only meant that we should not kill snakes in their natural, wild habitat, but that if they venture into heavily peopled areas, we should kill them (or if possible, return them back to the wild).
But all of this is just conjecture. It could just as well be that the Arizal advocated avoiding killing creatures altogether, even at the expense of human life.
It is also not proper to kill or despise lice, which are born and created out of sweat. This is true especially [of lice produced on the heads] of good people. Sweat is the excess [energy] of the person and his dross, and from it these lice are created; this being the case, it is a boon and a rectification for the person when lice are created out of the sweat of his body, for in this way his excess, dross, and evil is excreted. [Since they perform a positive function] we should not despise them.
Translated and adapted by Moshe-Yaakov Wisnefsky from Likutei Torah and Shaar HaMitzvot, parashat Noach; subsequently published in "Apples From the Orchard."
Reprinted with permission from Chabad of California. Copyright 2004 by Chabad of California, Inc. All rights reserved, including the right to reproduce this work or portions thereof, in any form, without permission, in writing, from Chabad of California, Inc.

Spontaneous generation I have a problem with the assertion (without qualifying comment) that lice are "born and created out of sweat." There is no evidence today that that is the case; rather all evidence supports the belief that lice are born out of eggs laid by other lice. The belief in spontaneous generation was first challenged in the 17th century CE by Francesco Redi, who showed by experiment that maggots, thought to be "born and created" from rotten meat in fact come from eggs laid by adult flies on rotten meat. There are those that believe that nature has changed, that in the Ari's time lice were, indeed, created from sweat but are no longer. There are others who believe that when our sages wrote of matters that can be investigated by science they expressed scientific ideas of their own era, since discredited. Both groups include many pious, shomrei mitzvot Jews. Given that readers of this column will include Jews of secular background, I think it's important to recognize the discrepancy.
I think it is clear that as the Holy Ari was a kabbalist he speaks of mystical matters.
Ie. Spirit and matter are connected, and while we do not always perceive that as we look only at the material he is speaking of the spiritual catalysts for natural phenomena.
On a spiritual level our excess energy manifests on the material plane as excess sweat. The fact that someone may experience lice comes in consequence of the excess energy and therefore acts as a tikkun causing some suffering that expiates the energy. (When the spiritual rectification is performed, so also on the natural plane it is possible that the problem will resolve).