A three-dimensional analogue of the classical direction problem is proposed and an asymptotically sharp bound for the number of directions determined by a nonplanar set in AG(3, p), p prime, is proved. Using the terminology of permutation polynomials the main result states that if there are more than (2 p-1 6 + 1)(p + 2 p-1 6 )/2 2p2 /9 pairs (a, b) F2 p with the property that f(x)+ag(x)+bx is a permutation polynomial, then there exist elements c, d, e Fp with the property that f(x) = cg(x) + dx + e.