The process is the same whether you catch them yourself or buy them live from the person who did. Only cook live crabs, because they deteriorate very quickly after they have expired.
You can simply throw the crabs in a pot of boiling water to cook them. Depending on the size of the crabs, it will take between 6 and 10 minutes for them to cook thoroughly. If the crab is alive when you start, the amount of cooking time has very little to do with safety - it’s more a question of whether the meat is underdone, overdone, or cooked just right. For blue crabs, six minutes is adequate; for a Dungeness, boil for 8 to 10 minutes.
The shells of many varieties of crab turn red when they have been adequately cooked.
If you want to clean the crabs before you cook them, you can kill them by tossing them into boiling water for 30 seconds or by cutting with a knife just behind the eyes to remove the head. Next, scrape out the gills that are found under flaps just over the legs. Then, turn the crab over. On the underbelly you will find the "tail" or "apron," a slightly-lifted triangular flap. Pull this off. Finally, rinse the crab and pop it back into the pot to finish cooking.