It's so simple, we create a giant transparent sphere made out of either extremely reinforced glass or plastic and surround it around a planet. What this does is it gives us the ability to create an atmosphere and even control the temperature and weather on a planet and make it suitable for life.
This is a billion-trillion dollar project BUT it will create a million jobs and help boost the economy and let us terraform planets.
YOU'RE WELCOME SCIENTIST.
-
A more feasible method would be to produce an unnaturally strong magnetic field through technological means that would retain an atmosphere. This would avoid the material problems associated with building a giant glass bubble. Your method, however could be feasible if self replicating machinery is used, given many large asteroids are available to be consumed.