Epistemic status: Not an expert. Pretty confident I have it right. Incorporated feedback from commenters, and asking for more. List of edits at the end.
What the Moderna vaccine does is it contains a piece of code (RNA) which asks your body to create a protein that is very similar to the SARS-CoV-2 spike protein (which it uses to attach to your cells), but modified in such a way that it is more stable, and doesn't change shape. Otherwise, the easiest place for the antibody to identify and attach to the protein gets hidden by the rest of the structure. Your body then says, "Hey, that's something new! Let's attack it!" and tries out a bunch of different things.
A difference with the mRNA vaccines is that there are no viral particles. The only thing it contains are the code (plus other code that doesn't get used to generate things, but are useful in keeping the rest of the code stable). The amount of RNA you get in your two shots would be all that's needed, and your body doesn't make extra strands of RNA that would ask for more spike proteins. In other words, you only get a protein that exists on the shell of the SARS-CoV-2 virus, and not there virus itself, so there is zero risk of infection.
Side effects are minimal. Less than 2% of the people get a fever, and most don't even have a headache. Just some muscle pain etc near the injection site. However, according to a commenter (see precog's comment below), there are some disadvantages, including the possibility that, while it might prevent disease, it might not prevent infection and transmission. Also, the lipids that hold the RNA might generate an immune response as well.
The Pfizer/BioNTech vaccine works slightly differently, but it's a similar idea. Have RNA code to produce the antigen to get an antibody response. It uses the same stabilization modification, which was discovered by Jason McLellan's lab in collaboration with the NIH.
These two are the first ever mRNA vaccines. mRNA vaccines are very modular, as well as easy to change and modify; most labs would be able to make their own vaccines with machines they already have. I've been following Moderna for a few years, and they were working on a MERS vaccine in the past. 4 days after the SARS-COV-2 genome was uploaded, they'd decided which sections they want to use, and which edits needed to be made, and they started manufacturing it (not mass production) literally the next day, and that was still in January.
edits: Incorporated information from precog (see his comment). Removed the self-propagating claim. Added a bit more information about Pfizer's vaccine. Changed wording regarding viral particles. Removed mention of a better immune response. Added disadvantages. Added clarification that there is zero risk of infection.