Edit
In light of the fact that the OP needs to access coordinates within the nested pictures, I recommend using Symbol 1's \scopenode
solution. However, as it stands, any fill in the enclosing node will obliterate the content.
However, you can modify the macro to put the contents of the enclosing node behind the material it encloses. For example,
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external,backgrounds}
\tikzexternalize
\tikzset{external/prefix=ffigurau/}
\makeatletter
\pgfdeclarelayer{scopenode}
\pgfsetlayers{background,scopenode,main}
\tikzset{%
% adapted from tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarybackgrounds.code.tex
on scopenode layer/.style={%
execute at begin scope={%
\pgfonlayer{scopenode}%
\let\tikz@options=\pgfutil@empty%
\tikzset{every on scopenode layer/.try,#1}%
\tikz@options%
},
execute at end scope={\endpgfonlayer}
},
}
% ateb Symbol 1: https://tex.stackexchange.com/a/362360/
\newbox\tikz@sand@box
\newcount\tikz@scope@depth
\tikz@scope@depth111\relax
\def\scopenode[#1]#2{% name=<enw>, at=<man>, anchor=<angor>
\begin{pgfinterruptboundingbox}%
\advance\tikz@scope@depth111\relax%
% process the user option
\begin{scope}[name=tempscopenodename,at={(0,0)},anchor=center,#1]%
% try to extract positioning information: name, at, anchor
\global\let\tikz@fig@name\tikz@fig@name%
\global\let\tikz@node@at\tikz@node@at%
\global\let\tikz@anchor\tikz@anchor%
\end{scope}%
\let\tikz@scopenode@name\tikz@fig@name%
\let\tikz@scopenode@at\tikz@node@at%
\let\tikz@scopenode@anchor\tikz@anchor%
% try to typeset this scope
% we only need bounding box information
% the box itself will be discard
\setbox\tikz@sand@box=\hbox{%
\begin{scope}[local bounding box=tikz@sand@box\the\tikz@scope@depth,#1]%
#2%
\end{scope}%
}%
% goodbye. haha
\setbox\tikz@sand@box=\hbox{}%
% now typeset again
\begin{scope}[local bounding box=\tikz@scopenode@name]%
% use the bounding box information to reposition the scope
\pgftransformshift{\pgfpointanchor{tikz@sand@box\the\tikz@scope@depth}{\tikz@scopenode@anchor}%
\pgf@x-\pgf@x\pgf@y-\pgf@y}%
\pgftransformshift{\tikz@scopenode@at}%
\begin{scope}[#1]%
#2
\end{scope}%
\end{scope}%
\pgfkeys{/pgf/freeze local bounding box=\tikz@scopenode@name}%
\global\let\tikz@scopenode@name@smuggle\tikz@scopenode@name%
\end{pgfinterruptboundingbox}%
% make up the bounding box
\path(\tikz@scopenode@name@smuggle.south west)(\tikz@scopenode@name@smuggle.north east);%
% draw something, not necessary
\begin{scope}[on scopenode layer]%
\draw[#1](\tikz@scopenode@name@smuggle.south west)rectangle(\tikz@scopenode@name@smuggle.north east);%
\end{scope}%
}
\makeatother
\begin{document}
\begin{tikzpicture}
\filldraw [blue] circle (5pt);
\scopenode[draw=red, fill=orange, name=bob, at={(2,2)}, anchor=south west]{%
\draw (0,0) coordinate (a) -- (1,1) coordinate (b);
}
\scopenode[draw=blue, fill=yellow, name=gog, at={(-2,-2)}, anchor=north east]{%
\draw [magenta] (1,1) coordinate (c) -- (0,0) coordinate (d);
}
\draw [->] (a) [bend right] to (c);
\draw [->] (d) [bend right] to (b);
\end{tikzpicture}
\end{document}

Original Answer & Explanation
When compiling externalised images, TikZ ignores all other pictures in the document (and 'expensive' commands, as well). This is designed to speed compilation by 'optimising away' irrelevant, but resource-hungry typesetting tasks.
You can always switch it off if you really need to do things this way.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\tikzset{%
external/prefix=ffigurau/,
external/optimize=false,
}
\begin{document}
%savebox definition
\newsavebox{\myBox}
\begin{lrbox}{\myBox}
\begin{tikzpicture}
\draw (0,0) -- (1,1);
\end{tikzpicture}
\end{lrbox}
%drawing the picture
\begin{tikzpicture}
\node[draw = red, fill = orange] {\usebox{\myBox}};
\end{tikzpicture}
\end{document}
However, if you have many pictures (and why else would you want to use externalisation?) this will greatly slow compilation whenever a picture needs to be compiled. For each new or changed picture, all pictures will be compiled and all 'expensive' commands executed.
I don't see why you can't do the following instead. This code uses the save box, but only to prevent the picture being typeset in the main document. Otherwise, the save box is simply ignored.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\tikzset{%
external/prefix=ffigurau/,
}
\begin{document}
%savebox definition
\newsavebox{\myBox}
\tikzsetnextfilename{mybox}
\begin{lrbox}{\myBox}
\begin{tikzpicture}
\draw (0,0) -- (1,1);
\end{tikzpicture}
\end{lrbox}
%drawing the picture
\begin{tikzpicture}
\node[draw = red, fill = orange] {\includegraphics{ffigurau/mybox}};
\end{tikzpicture}
\end{document}
It makes no sense to say you can't include the image here as that is literally what you are doing when you externalise it anyway. (The save box effectively just does \includegraphics{...}
and then you \usebox{...}
, so you might just as well \includegraphics{...}
directly.
\begin{document}
does not help, did you try to put them after\begin{tikzpicture}
?tikzpicture
environment in the savebox (i.e.\tikz
commands only). I've updated the MWE accordingly.\begin{tikzpicture}
instead of\tikz{}
? As long as I can tell they are the same. (except you have verbatim/listings things inside, of course.)