feat(python): outbound raw TCP/UDP sockets + complete the Pyodide FS hooks#142
Merged
Conversation
Back Python's socket module with host sockets (outbound TCP connect/send/recv, UDP sendto/recvfrom), governed by the network policy + DNS egress guard like the HTTP bridge: - python.rs: SocketConnect/Send/Recv/Close + UdpCreate/Sendto/Recvfrom RPC methods, port/socketId wire fields, and Socket*/Udp* response payloads - execution.rs: handle_python_socket_rpc_request opens host TcpStream/UdpSocket per process (require_network_access + filter_dns_safe_ip_addrs), short read timeout so a recv RPC never stalls the shared event loop - state.rs: per-process PythonHostSocket registry - runner: socket bridge methods + a socket.socket shim that polls recv/recvfrom to emulate blocking semantics Listeners (bind/listen/accept) are out of scope — outbound only. Test: python_runtime_supports_raw_tcp_and_udp_sockets drives TCP + UDP echo servers through Python's stdlib socket module. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jun 28, 2026
|
🚅 Deployed to the secure-exec-pr-142 environment in rivet-frontend
🚅 Deployed to the secure-exec-pr-142 environment in secure-exec
|
456bcbc to
7a36a35
Compare
FS hooks: symlink, readlink, lstat, and setattr->host (chmod/chown/utimes) — every Emscripten node_op/stream_op. lstat lets pre-existing host symlinks be detected as link nodes; setattr is host-first; chmod/utimes mirror to the host shadow only when the entry already exists there (never creating empty stubs); chown applies uid/gid independently (keeps the unchanged side). Socket hardening: per-process registry bounded by the VM max_sockets limit, read+write timeouts so recv/send can't wedge the shared loop (recv uses a short host poll + a capped guest-side backoff), connect/sendto routed through the loopback-connect gate (blocks DNS-rebind to sidecar-local ports), and host errors mapped to the right OSError/errno. Tests: python_runtime_supports_raw_tcp_and_udp_sockets, python_runtime_supports_symlink_readlink_and_metadata (now also covers a host-preexisting symlink); full python_suite green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
7a36a35 to
226624a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two related pieces that finish out the guest-Python runtime, combined into one PR (two commits).
1. Raw TCP + UDP sockets
Backs Python's stdlib
socketmodule with host sockets — same synchronous-bridge + network-policy model as the HTTP/DNS bridge.connect/send/sendall/recv/close) and UDP (sendto/recvfrom/close),settimeout/setblocking.require_network_access+ the DNS egress guard (resolve-once-and-pin, restricted ranges refused).recvRPC never stalls the shared event loop (the Python shim re-polls to emulate blocking).bind/listen/accept) are out of scope — outbound only.2. Complete the Emscripten FS hooks
Closes the remaining gaps so the custom FS backend implements every node_op/stream_op the FS layer dispatches (verified against MEMFS's
ops_table).symlink(was anENOSYSstub) andreadlink(was missing, no link-node) now work.setattrnow propagateschmod/chown/utimesto the host VFS (was in-isolate only).Tests
python_runtime_supports_raw_tcp_and_udp_sockets— TCP + UDP echo servers through stdlibsocket.python_runtime_supports_symlink_readlink_and_metadata—os.symlink/readlink/path.islink/chmod(host cross-checked)/utime.python_suitestays green.Supersedes #140 and #141 (closed in favor of this combined PR).
🤖 Generated with Claude Code