There are two adiabatic containers filled with an ideal gas. In container A work is done which eventually turns completely into heat, leading to a temperature difference between container A and container B. Does a Carnot-efficient heat engine between the containers recover all the work that was initially done in container A?
The short answer is "no".
In the comments, Chester Miller rightly points out that the work done turns into internal energy, not heat, but it looks like you are indicating a heating process. See Is thermal/heat energy the same thing as internal energy? for the distinction.
Since it is a cycle, the Carnot cycle requires both heating and cooling. Since cooling is the loss of internal energy, and not through work, some of the energy added by heating container A is not converted to work. The portion of the heating energy which is converted to work is called the efficiency of the cycle. For a Carnot cycle, it is given by $\eta = 1 - T_L / T_H$ (wikipedia). Unless $T_L = 0$, your engine will have to cool down and lose some of its energy thermally.
What makes the Carnot cycle special is that it conserves entropy. That means that the cycle can be reversed without strongly violating the Second Law of Thermodynamics. (Technically the Second Law says "entropy always increases," but for a Carnot cycle, pretend it says "entropy never decreases.") So while not all of the energy is converted to work, it is all still "accessible" in that it could be returned to where it came from.