You can definitely ask. The answer may be “No,” but nobody should consider that to be a bad or inappropriate question.
If they won’t show you the code, you should definitely take that into account when you decide whether you want to accept an offer. I would take it as a sign that at least one of the following things is true:
- The code is so horrible that they know you’ll run away screaming.
- The company has an ultra-secretive trust-nobody culture (which I would hate).
- The company thinks they have such amazing code that just glancing at it would turn you into a superstar competitor. (In other words, they’re self-deluded morons.)
- They have glaring security holes that they hope to keep secret.
- The people who are interviewing you don’t know how to get the code themselves. (In which case you are not talking to the right people.)