If i am correctly understanding what happens in the code, we use j=√−1 , a=4√17 , and the tower of algebraic number fields F=Q(a,j)↑k=Q(j)↑Q and ask for the group G=Gal(F:Q), then check for each g in G if it stabilizes j.
This can be done by no longer using k as follows:
R.<x> = PolynomialRing(QQ)
F.<j, a> = NumberField([x^2 + 1, x^4 - 17])
L.<w> = F.galois_closure()
G = L.galois_group()
J = (x^2 + 1).roots(ring=L, multiplicities=False)[0]
A = (x^4 - 17).roots(ring=L, multiplicities=False)[0]
Stab_J = [ g for g in G if g(J) == J ]
Note that working like this we obtain a list, not a subgroup of G.
sage: Stab_J
[(), (1,2,4,3)(5,7,8,6), (1,3,4,2)(5,6,8,7), (1,4)(2,3)(5,8)(6,7)]
sage: list(G)
[(),
(1,2,4,3)(5,7,8,6),
(1,3,4,2)(5,6,8,7),
(1,4)(2,3)(5,8)(6,7),
(1,5)(2,6)(3,7)(4,8),
(1,6)(2,8)(3,5)(4,7),
(1,7)(2,5)(3,8)(4,6),
(1,8)(2,7)(3,6)(4,5)]
sage:
Here, we use J,A - which are elements in the "abstract field" L, so that there are maps j→J and a→A from F to L.