Code to or for the lab?

Solution 1:

In the circumstances you describe both "key to" and "key for" are acceptable.

Likewise both "code for" and "code to" are acceptable.