A plugin gets an input pipe and an output pipe—not your home directory.
This is the smallest complete compartment in the demo set. The host packages one Lua worker, starts it with Easybox, and sends exactly the descriptors needed to transform one text message.
The expected output is a single line: > hello from the host.
1. Package source without granting source-tree access
Emilua checks source_tree_cache before the filesystem when loading modules in a child. The host reads the trusted plugin file and assigns its contents to the cache entry used as the worker’s entry point.
init.lua—explicit source transfer
local worker = easybox.new{
module = fs.path.new('/plugin.lua'),
source_tree_cache = {
['plugin.lua'] = util.read_source(root / 'plugin.lua'),
},
stdout = 'share',
stderr = 'share',
}
The child can load plugin.lua, but it does not need to read the host’s source tree through ordinary filesystem calls.
Read the shared source-loading helper. It runs in the trusted host before the sandbox exists.
2. Create only the required channels
pipe.pair() returns a connected pair. The host releases the two child-side descriptors so actor messaging can transfer ownership, then closes its own copies after the send.
init.lua—capability creation and transfer
local child_input, host_output = pipe.pair()
local host_input, child_output = pipe.pair()
child_input = child_input:release()
child_output = child_output:release()
worker:send{ input = child_input, output = child_output }
child_input:close()
child_output:close()
The worker’s inbox is the entry point. The message tells it which resources to use for this request.
3. Keep host I/O concurrent
A host fiber writes the request and closes the pipe while the main path reads the response. This prevents a full pipe buffer from deadlocking the exchange.
init.lua—concurrent write
spawn(function()
stream.write_all(host_output, 'HELLO FROM THE HOST')
host_output:close()
end):detach()
print(util.read_to_eof(host_input))
Emilua’s initiating functions suspend the calling fiber rather than stopping the whole VM. The example uses that property for a real producer/consumer exchange.
4. Preserve real I/O errors
The worker appends each chunk to a byte_span. EOF ends the read loop; any other error is re-raised instead of being silently converted into a successful short response.
plugin.lua—EOF versus failure
if ok then
contents = byte_span.append(contents, buf:first(value))
elseif value == asio_error.misc.eof then
break
else
error(value)
end
After reading, the worker lowercases the buffer, prefixes > , writes it to the supplied output pipe, and closes both descriptors.
5. Run and verify
mise run demo:pipe
> hello from the host
The displayed output is the transformed text produced by the sandboxed worker, not a hard-coded success message in the host.
Before adapting it
This example deliberately accepts a small fixed input. Real plugin hosts should bound input size, memory use, execution time, and queue depth. Review Easybox’s current policy and platform requirements before treating the compartment as a production security boundary.