In order to investigate the relationship between production and taxation we develop an agent-based model in which complex aggregate regularities emerge from the interaction among heterogeneous agents. We analyze the dynamics of financially fragile firms linked to a banking sector when a profit tax is introduced. Our aim is to study the role of the public sector in stabilizing and boosting economic growth and to verify the Domar-Musgrave hypothesis that the compensation of losses increases the risk attitude of the productive system. In this setting, a "marshallian" pure profit tax reduces the probability of firms' bankruptcy, mitigating aggregate fluctuations and creating the conditions for capital accumulation and growth. Accordingly, the public sector works as an insurance market enhancing the efficiency of the economy and reducing the probability that small idiosyncratic shocks generate large aggregate fluctuations. The model also reproduces industrial dynamics stylized facts and explores the effect of taxation on the interplay among individual behavior, meso-regularities and macroeconomic properties.