I’m not sure whether this is a cocoon or an egg sac. I know spiders spin cocoons for molting and other reasons. I also know they spin silk around their captives and also protect their eggs in silk. In the brief time I researched, I didn’t find any conclusive evidence for what this was. My guess is that it is a cocoon.