The discourse on the Group Protection is mentioned in the Khanda Vatta Jataka Story. According to the story, the Bodhisatta (the future Buddha) was an ascetic in a previous life. He heard his fellow ascetics complaining about the dangers from snakes and other creatures. He therefore instructed them to recite this protective Khanda Paritta not only for protection against snakes, but also against other poisonous creatures.
According to the Culavagga Vinaya Pitaka Text, this Sutta was composed by the Buddha, when a certain monk died of a snake bite. The Buddha declared that this would not happen if the monk had radiated loving kindness towards the four group of snakes. The Buddha then recited a stanza which caused loving kindness to pervade all beings. The passage following the stanza does not seem to be part of the original Sutta. It is a request by the individual to all snakes, poisonous insects etc mentioning that they have been protected by the implorer (though previous song of loving kindness) and they are requested to get away. This is followed by an expression of homage to the Lord and the Seven Buddhas.