We present a generalization of the notion of perfect codes: perfect codes over graphs. We show an infinite family of 1-perfect codes in second powers of graphs and we prove the nonexistence of nontrivial 1-perfect codes over complete bipartite graphs with at least three vertices.