Abdullah bin Masud reported,

While we were with the Prophet ﷺ in a cave at Mina, the surah al-Mursalat was revealed to him. He was reciting it, and I was receiving it directly from his mouth, his mouth still moist with its words, when suddenly a snake darted out at us.The Prophet ﷺ said, "Kill it!"We rushed at it, but it escaped.The Prophet ﷺ then said, "It has been spared your harm just as you have been spared its harm."

Bukhari 1830

Sahih

حدثنا عمر بن حفص بن غياث حدثنا أبي حدثنا الأعمش قال حدثني إبراهيم عن الأسود

عن عبد الله رضي الله عنه قال

بينما نحن مع النبي ﷺ في غار بمنى إذ نزل عليه والمرسلات وإنه ليتلوها وإني لأتلقاها من فيه وإن فاه لرطب بها إذ وثبت علينا حية فقال النبي ﷺ اقتلوها فابتدرناها فذهبت فقال النبي ﷺ وقيت شركم كما وقيتم شرها

البخاري 1830صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Game animal penalties
Chapter
What animals the pilgrim in ihram may kill
Numbering
Darussalam 1830