Yes you can dye the silk cocoons with the catepillar still inside. However that being said you need to get the cocoons dry as soon as possible to prevent rotting (the catepillar rots). You will get one or two that are stained due to the critter inside, but out of a batch of 60 cocoons I dyed only two were stained.
I dye my cocoons using natural dyes, if you remove the sericin from the cocoons, after they have been dyed, you will loose the color. The cocoons float on top of the dye bath, if you don't cut them open, I turn them frequently using a large skimmer I have.
Once they are dyed I remove them, rinse them right away, and the run them through a dedicated salad spinner. Make sure all of your dye equipment is for dyeing ONLY! I then put them on a cooling rack to dry. You could use a hair dryer on them as well.
You can also dye the cocoons in the indigo vat, good way to get greens. I take my salad spinner basket put the wet cocoons into the basket and submerge it carefully into the dye vat, now you know why I said dedicated equipment. I leave it about 30 seconds bring them out quickly so as to not get dye liquid back into the vat, let them oxidize and drain into my sink. I do this as many times as necessary until I get the desired shade of blue.
This also worked with the silk carrier rods I dyed last night. The carrier rods take dye differently, there are areas that are bright blue, form the indigo, and other areas that are still that silvery natural color. It's a very interesting effect. They also softened up a bit in the dyeing process, that may be due the high pH of my indigo vat and all of the soda ash in the vat.
Indigo stains on your equipment? Clean it off with a baking soda paste.
Pictures coming soon.