Legal depending on the insulation.
300.3(C) Conductors of Different Systems.
(1) 600 Volts, Nominal, or Less. Conductors of ac and dc
circuits, rated 600 volts, nominal, or less, shall be permitted
to occupy the same equipment wiring enclosure, cable, or
raceway. All conductors shall have an insulation rating
equal to at least the maximum circuit voltage applied to any
conductor within the enclosure, cable, or raceway.
Exception: For solar photovoltaic systems in accordance
with 690.4(B).
FPN: See 725.136(A) for Class 2 and Class 3 circuit
conductors.