In this article we establish for the first time the Cs boundary regularity of solutions to nonlocal elliptic equations with kernels K(y)≍∣y∣−n−2s. This was known to hold only when K is homogeneous, and it is quite surprising that it holds for general inhomogeneous kernels, too. As an application of our results, we also establish the optimal C1+s regularity of solutions to obstacle problems for general nonlocal operators with kernels K(y)≍∣y∣−n−2s. Again, this was only known when K is homogeneous, and it solves a long-standing open question in the field. A new key idea is to construct a 1D solution as a minimizer of an appropriate nonlocal one-phase free boundary problem, for which we establish optimal Cs regularity and non-degeneracy estimates.