I will have a 12-hour layover in Paris Charles de Gaulle on August 21/22, between 10 pm and 10 am. What to do in the middle of night? Is it relatively safe to take a train or taxi into Paris and go for a late dinner and sightseeing? Are there sightseeing companies to take me around from the airport into Paris and back at that time of night?
I think the biggest problem you will have is getting out of CDG and into the centre of Paris quickly enough. In all likelyhood, if you don't land until 10pm, it is going to be 11:30pm or midnight before you are in the centre of Paris.
It is not impossible to eat that late in Paris, just harder to find something decent.
As for sightseeing, a quick search online revealed there are nighttime tours, just not that late. Some museums are open late, but again not that late. The Metro & RER typically runs until ~1am.
Paris though is an attractive city at night and you can probably put together your own walking & taxi tour, or maybe you could rent a bike (though the Velib Metropole scheme has had some troubles recently). I do wonder though if that is sufficient to fill the entire night.
Lastly, getting information or help that late could be difficult. Do your research before you arrive and come up with a plan.
Getting back to CDG by 8am shouldn't be a problem.
First all, you'll have to check you have the appropriate paperwork to actually enter France. For many citizenships you don't need anything, for others you may need to arrange a visa ahead of time.
Also, you need to check if your luggage is checked through (both flights on the same ticket, and the stop counted as a layover, not a stopover). If you need to collect your luggage, you probably won't be able to check it back right away (though the rules vary depending on the airline for the second flight), and you would then have to carry it with you.
The next step is to get to Paris. You can take a taxi, ride the RER, or take Le Bus. For the last two (especially the RER), check schedules ahead of time, and be attentive to any service changes due to track works which may affect those schedules.
If you have luggage and/or if you want to get a few hours sleep, you'll have to get to a hotel (you want to book that in advance and make sure they have a 24h reception, which is the case for larger hotels, but not necessarily for the smaller ones).
If you want to eat, there are few options to eat that late. I would recommend Le Pied de Cochon near Les Halles (close to the Louvre), which is open 24/7 and where you will find very typical french fare.
You may find a few (probably overpriced) places on the Champs-Elysées, but otherwise, other than fast food outlets, the choice will be pretty limited at that hour.
Depending on where you eat and sleep, you could have a nice walk through Paris. Many monuments stay brightly lit and you could see quite a few things. You could for instance start from Le Pied de Cochon, walk towards the Seine, and take a right along the Seine until you reach the Eiffel Tower, then walk up the Trocadero, take avenue Kleber to the Arc de Triomphe. It'll probably take 2 good hours.
Don't forget to fully charge your phone beforehand and take a power bank, between photos and maps you'll probably drain the batteries.
Then get a short night's sleep, and get back to CDG in the morning.