I'd like to give a little more general answer.

The problem of finding the minimum distance between two (convex) sets is a mainstay of the optimization theory. In fact, even finding the distance of a point to an hyper plane is such a problem.

So in your case, given that $A,B$ are compact closed sets, your formulation can be solved fairly efficiently as long as you can express both sets in closed form. Indeed, the problem is a convex optimization problem, which can be solvable efficiently in many cases.

For instance, if $A,B$ can be expressed in terms of the intersection of convex constraints, i.e. some functions $g^i_B(),g_A^i()$,

$min_{x,y} ||x-y||_2$

$ s.t.$

$\quad g_A^i(x)\leq 0\quad i=1,\ldots,n_A$

$\quad g_B^i(y)\leq 0\quad i=1,\ldots,n_B$

then any algorithm for general convex optimization can do. If also all the functions can be expressed in conic form (see Ben-Tal, A., & Nemirovski, A. (2001). Lectures on modern convex optimization: analysis, algorithms, and engineering applications) then the problem can be solved in polynomial time.

I myself have experienced solving some of this problem to test the optimization software produced the company I work in. Our solver, MOSEK, deals with conic optimization, which includes a fairly large number of possible convex set you can think about.

Of course, if your set is particularly structured or performance is a major issue, you must look for specialized algorithms. But as an advise, if you can I would use a general purpose solver as a basic, and usually robust, benchmark to compare against.