Measure the length of the box edges at the top or bottom of your box, depending on where you want your molding applied. Write down the length of the long side and short side of a rectangular box. Measure the length of one side for a square box, since all sides will be equal.
Select your molding. Small moldings, less than two inches tall, work best. Measure the thickness of your molding from the back to the thickest point on the face and double it. Add the doubled thickness of your molding to the side measurements from your box and cut two pieces at the long dimension, and two for the short sides (or four equal pieces for a square box). Cut the pieces using a miter saw set to 90 degrees.
Stand your molding on the miter saw with the square bottom edge on the table and the back against the fence. Set the blade to 45 degrees -- right of center for a right end, or left of center for a left end. Align the blade with the front corner of your molding, just to the right of a right end cut, and just to the left of a left end cut. Cut all four pieces on both ends, one right and one left.
Apply wood glue to the back of the molding and position one piece against the side of the box with a matching length. The mitered ends should extend out from the corners of the box. Align the top edge with the top of the box for top edge molding, or the bottom edge with the bottom of the box for bottom molding.
Nail the molding to the box with a pin nailer, using nails at least 1/8 shorter than the thickness of the molding and box side put together. Use at least two nails, or one every 4 inches. Fit the remaining three pieces to the other faces of the box, so that the corners match up to create 90-degree corners.