Technically, the question is if you prepare the computer beforehand for this task or not and also how strictly you define a "piece of code", as two programs can yield the same executed instruction sequence due to branches.
In a lose definition of "piece of code", if you prefer the computer beforehand, you could create a virtual machine that creates a history of executed instructions (or alternatively and space saving, the executed programs) and send this history in real time using public key cryptography to a trusted machine, the "history keeper", which marks the history stream with time stamps. For a lower security level you could also save that history locally, outside the content accessible from users inside the virtual machine. While there are still possibilities of tampering (e.g. compromising the virtual machine), in a company where the virtual machine startup is reasonably secured (no usable USB ports, BIOS locked, boot sequence not changeable using "save mode" or something, workers are under supervision so they can't modify the hardware and remove/switch components), this would not give you 100% security but work reasonably well for many cases.
Legally, it depends on the jurisdiction and the circumstances. At least in Germany and the U.S.A., criminal law needs a much higher certainty then civil law, so I would assume that enough for a civil law process but depending on the circumstances for a criminal law one.