The NESTT mod allows you to build factories inside a train. But it doesn't allow you to nest the trains inside eachother and it is limited to the NESTT game mode.
Maybe you could add space inside trains too? The amount of space would depend on amount of wagons, and you should be able to connect the inner walls of the cargo wagons with the cargo wagon box in the outside world of the train.
Would be nice if my trains that go between stations picked up plates and delivered repairpacks to outposts without any factories needed on land.