<p>I want something that looks like a file handle but is really backed by an in-memory buffer to use for I/O redirects. How can I do this?</p>

This may not be possible.
GHC
, at least, seems to require a handle to have an OS file descriptor that is used for all read/write/seek operations.
See
```
/libraries/base/IOBase.lhs
```
from the GHC sources.
You may be able to get the same effect by enlisting the OS's help: create a temporary file, connect the handle to it and then memory map the file for the I/O redirects. This way, all the handle I/O would become visible in the memory mapped section.