One of the 39 Melachot is "Saad"-trapping. This was done in the Mishkan in several forms. They trapped the Hilzaon fish in order to use its blue dye for the Tehelet. They also trapped the Tahash, to use its skin to drape over the roof of the Mishkan.
Maran brings a practical application of trapping a wild bird into a caged area. Doing so is a Torah violation of Shabbat. The question arises what to do if a bird flies into one’s house. Is he allowed to close his door? He may want to keep other birds from entering, or prevent the cold form penetrating his house or he may just want to go to sleep and leave himself protected. Does closing the door constitute a violation of Saad?
The Mishna Berura cites the Hayeh Adam (Rav Abraham Danzig of Vilna, 1748-1820) who permits closing the door if his intention is to ward off the cold or other nuisances, since he does not have any intention to trap the bird. Hacham, Ovadia explains that such a trapping would not be a Torah violation anyway, since the house is so big, the bird remains free, even with the door closed. Therefore, this case is a "Pesik Resheh D’lo NIcha Leh B’drababnan"-a Rabbinic Melacha unintentionally performed automatically, which is permitted.
SUMMARY
If a bird flies into a house, it is permitted to close the door in order to protect himself from the cold or other annoyances.