Antibiotics block biochemical pathways important for bacteria. Many bacteria make cell wall to protect them. Antibiotics (Penicillin) prevent the making of cell wall. So the bacteria become unable to make cell walls. So they die easily.
The penicillin do not affect the human cells because, human cells do not have a cell wall. Penicillin can work against any bacterium that forms cell wall.But viruses do not use these pathways at all. Therefore antibiotics do not work against viral infections