  In this article we establish for the first time the $C^s$ boundary regularity
of solutions to nonlocal elliptic equations with kernels $K(y)\asymp
|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 $C^{1+s}$ regularity
of solutions to obstacle problems for general nonlocal operators with kernels
$K(y)\asymp |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 $C^s$ regularity and
non-degeneracy estimates.
