Not much different from other industries, other than scale and reach. Took many decades to regulate out killing workers and customers for profit, some are still barely regulated.
The Jungle is famously about horrifying working conditions back in the day and was critical for gaining public support for legislation and regulations. "Capitalism" didn't improve the working conditions; regulations did.
Fire codes have been very beneficial, but they don't move the needle on overall life expectancy. Nor have historical communist societies shown any particular interest in workplace safety.
Besides, free markets do not allow imprisoning workers in a factory (or anywhere else).