Step 1: Getting Started
Sometimes needed: cardboard, paint.
Plug the glue gun in so it can heat up while you think.
Closed cell foam is saved from appliance or equipment boxes. LDPE is what you want. It's easy to glue in place, and very easy to cut. If you don't have a single piece of foam big enough to fill a particular area, you can glue smaller pieces up to fit.
Step 2: The Case of the Upgraded Dremel
Step 3: Hold-downs
Sometimes after an object is well cradled from sides and below, it needs to be braced from above by a foam block glued to the box lid. In this case, make the best measurement possible for the required thickness of foam, cut it just a bit thicker, set the foam on the object, apply glue to the top of the foam, then close the lid on it. After a minute, open the lid; the foam should be firmly glued, and in the right place. Now when you close the lid, the foam clamps the object in place.