Skip to content

Commit 7428860

Browse files
authored
Merge pull request #123 from dzerik/feat/popen-python
feat(python): streaming-stdio popen — Sandbox.popen + Process (RFC #67)
2 parents e346175 + e26e9d0 commit 7428860

4 files changed

Lines changed: 805 additions & 27 deletions

File tree

python/src/sandlock/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
)
1515
from .inputs import inputs
1616
from .handler import Handler, NotifAction, HandlerCtx, ExceptionPolicy
17-
from .sandbox import Sandbox, BranchAction, parse_ports, Change, DryRunResult
17+
from .sandbox import (
18+
Sandbox, BranchAction, parse_ports, Change, DryRunResult, StdioMode, Process,
19+
)
1820
from ._profile import load_profile, list_profiles
1921
from .exceptions import (
2022
SandlockError,
@@ -49,6 +51,8 @@
4951
"parse_ports",
5052
"Change",
5153
"DryRunResult",
54+
"StdioMode",
55+
"Process",
5256
"Protection",
5357
# Handler ABI
5458
"Handler",

python/src/sandlock/_sdk.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,22 @@ def confine(policy: "PolicyDataclass") -> None:
317317
_lib.sandlock_handle_port_mappings.restype = ctypes.c_char_p
318318
_lib.sandlock_handle_port_mappings.argtypes = [_c_handle_p]
319319

320+
# Streaming-stdio popen (RFC #67): create+start a live handle with per-stream
321+
# StdioMode; each piped stream's owned fd is returned through its out pointer.
322+
_lib.sandlock_popen.restype = _c_handle_p
323+
_lib.sandlock_popen.argtypes = [
324+
_c_policy_p,
325+
ctypes.c_char_p,
326+
ctypes.POINTER(ctypes.c_char_p),
327+
ctypes.c_uint,
328+
ctypes.c_uint32, # stdin_mode
329+
ctypes.c_uint32, # stdout_mode
330+
ctypes.c_uint32, # stderr_mode
331+
ctypes.POINTER(ctypes.c_int), # out_stdin_fd
332+
ctypes.POINTER(ctypes.c_int), # out_stdout_fd
333+
ctypes.POINTER(ctypes.c_int), # out_stderr_fd
334+
]
335+
320336
# Result
321337
_lib.sandlock_result_exit_code.restype = ctypes.c_int
322338
_lib.sandlock_result_exit_code.argtypes = [_c_result_p]

0 commit comments

Comments
 (0)