(Magma) [p: p in PrimesUpTo(10^6) | Set(Intseq(p)) subset [1, 2, 9]];
(PARI) primes_with(n=50, show=0, L=[1, 2, 9])={for(d=1, 1e9, my(t, u=vector(d, i, 10^(d-i))~); forvec(v=vector(d, i, [1+!(L[1]||(i>1&&i<d)), #L]), ispseudoprime(t=vecextract(L, v)*u)||next; show&&print1(t", "); n--||return(t)))};
primes_with(, 1, [1, 2, 9])
(Python)
from gmpy2 import is_prime
from itertools import count, islice, product
def primes_with(digits): # generator of primes having only set(digits) as digits
S, E = "".join(sorted(set(digits) - {'0'})), "".join(sorted(set(digits) & set("1379")))
yield from (p for p in [2, 3, 5, 7] if str(p) in digits)
yield from (t for d in count(2) for s in S for m in product(digits, repeat=d-2) for e in E if is_prime(t:=int(s+"".join(m)+e)))