Is it safe to cut off the single-plug end of an extension cord and replace it with several regular receptacles and a metal box? Should the box itself be grounded?
I suppose it's safe as long as you wire it properly, including a secure attachment between the box and the cord to prevent the cord from pulling out. It certainly is not code-compliant, but temporary wiring like an extension cord isn't covered by electrical codes I believe. Yes, I would ground the box. (Depending on which outlet you install, it may be grounded automatically with the receptacle mounting screw, but I would do it with a pigtail anyway.
But why wouldn't you just use a power strip instead? Definitely easier and safer, probably similar in price to buying the parts individually.
This would be considered to be temporary construction power equipment. According to OSHA rules (1910.305, 1926.405) there are specific requirements and the assembly is not for permanent use (running your hand saw for various jobs on the property vs running your freezer long term). Link to OSHA as they're not going away anytime soon: Acceptable Job-Made Extension Cords
The major focus is on using boxes meant for this type of use (boxes with no coined knockouts or that use screw-in knockout plugs), making sure all grounds are intact (including the metal box), neutral and hots properly routed so plugging the assembly in or items into the assembly will not reverse polarity and proper strain relief is supplied (no romex squishers) for the cord.
NOTE: While OSHA rules don't apply to DIY, the spirit of the rules is to increase your safety so Joe Electron doesn't escape through you!
Is it safe? Maybe.
When you purchase an extension cord, that cord has been designed and tested to operate properly under certain circumstances. Once you modify the cord in any way, you've voided any listing or labeling on the cord (UL listing, etc.). If there is ever a fire, this could be a factor (but that's a legal issue, and outside the scope of the site).
If you know what you're doing, use properly sized cord, use the right box, and connect everything properly. Then yes, this can be done safely. However, if you don't know what you're doing, this can go horribly wrong.
It's not uncommon for homeowners and DIYers to be cheap. Because of this, they are likely to purchase lower end products. In the case of an extension cord, that means a smaller gauge wire (typically 16 AWG). In its unaltered state, this is almost never a problem.
Say you plug in your 12 Amp circular saw. Well the 16 AWG wire is rated at 18 amperes, and it's designed so only a single device can be connected at a time, so there is no problem.
Now lets say you've modified the cord, and attached a single duplex receptacle. you connect two devices, and draw a total of 20 amperes. Everything seems fine, since the receptacle will handle 20 amps, and the breaker back at the panel is also rated at 20 amps. The cord however, is only rated at 18 amperes. Now you start to smell something funny, and soon magic smoke begins to emit from the cord. Maybe you notice in time, maybe you don't.
You'll also want to consider the environment you'll be using the cord in. If you're planning to use the cord only in the shop, then a metal box might be fine. If you think you might ever use the cord outside, you might want to consider a weatherproof box and cover.
According to the manufacturer, modifying the cord in any way means the product is damaged and should be discarded. Modify extension cords at your own risk