The following is the minimal reproducing example, if you use debian system, one can install octave by snap or apt easily.
\documentclass[english]{article}
\title{Minimal example of octave with knitr for Rnw file}
\author{Xudong Sun}
\begin{document}
\maketitle
<<engine='octave', engine.path='/snap/bin/octave', results='markup', echo=TRUE, out.width=5>>=
x = -10:0.01:10
@
\end{document}
The output text runs out of margin:

Any solutions?
You can simply add the white background ;)
F.e.:
... but if you want to save "default dimensions of the bg area" you can use f.e: