You can sometimes approximate this but there is no completely reliable method, moreover, the methods available are more likely to fail as program complexity goes up (especially games tend to not behave well). At the end of the day, all available methods rely on some form of interception or wrapping of the original native program, and have varying overhead and likelihood of 'leaks', not to mention incompatibilities that may cause programs to just crash.
The following options are listed in vaguely decreasing order of reliability & overhead, with the most reliable and highest overhead at the top.
Run your application in a virtual machine (VM)
This generally has quite high overhead, and is generally not suitable for anything graphically intensive (e.g. games - additionally, anticheat tends to be unhappy about VMs). You're effectively running a whole separate OS that can then be contained within a single file (virtual disk).
So you'll have CPU, RAM and disk overheads, and GPU passthrough is typically fairly unreliable for gaming purposes (consumer drivers basically do not support it). Most other applications will run fine, though the user experience does suck a little (you have little to no integration with other applications on the host OS).
On the plus side, there's basically no chance of leaks unless it's malware dedicated to breaking out via a vuln in the hypervisor.
This is moderately portable, in that you can store the VM on portable media and run it on another machine with a compatible hypervisor installed.
In Windows probably the best hypervisor these days is probably Hyper-V. VMware Workstation has traditionally had the best GPU virt, but VMware is... not in a great place since the Broadcom acquisition. Virtualbox is another option but its GPU virt has traditionally been quite poor.
Run your application through a filesystem isolation layer
The classic tool for doing this in Windows is Sandboxie. This works by intercepting Windows API calls from a designated application, including filesystem calls, and redirecting them to a different location.
Some games work in this, some don't. Ones that have an anticheat are unlikely to work (anticheat does not like any kind of injection/interception... seeing a pattern here?).
Other applications largely work, though more complex ones (including web browsers) do break from time to time. It really depends on what the application tries to do, whether Sandboxie has implemented the necessary interception, and whether it's even possible to intercept that functionality.
This is the "middle ground", almost a VM-lite. You get some of the isolation typical of VMs, but without running a whole OS. Unfortunately, it's also lacking some of the completeness of VMs.
I was going to say this option is not very portable, but it looks like that's changed with recent versions.
Run your application through a lightweight wrapper
This is where things get really iffy. It's sometimes, partially possible to redirect parts of application writes. This is the approach PortableApps uses: it sets up an environment (modifies env variables, restores registry entries) before launching an application, and after the application closes it then tries to clean up (backup registry entries). There's a library of pre-wrapped apps, and it's possible to make your own wrapper.
The downside is this only works if the application plays nice and actually uses those environment variables. This does nothing to stop the application from writing where it wants to. It also does not play nicely with applications that install complex components (some shared libraries, etc.).
Which brings us back to the original answer of there is no universal answer. The best approach depends on why you want this, and there may be other approaches more appropriate for specific use-cases.