Skip to content

feat(python): outbound raw TCP + UDP sockets in the Pyodide bridge#140

Closed
NathanFlurry wants to merge 1 commit into
mainfrom
python-sockets
Closed

feat(python): outbound raw TCP + UDP sockets in the Pyodide bridge#140
NathanFlurry wants to merge 1 commit into
mainfrom
python-sockets

Conversation

@NathanFlurry

Copy link
Copy Markdown
Member

Adds outbound raw TCP and UDP sockets to guest Python by backing the stdlib socket module with host sockets — the same synchronous-bridge + network-policy model as the existing HTTP/DNS bridge.

What works

  • socket.socket(AF_INET, SOCK_STREAM)connect / send / sendall / recv / close
  • socket.socket(AF_INET, SOCK_DGRAM)sendto / recvfrom / close
  • settimeout / setblocking (blocking emulated by polling)
  • Egress is governed by require_network_access + the DNS egress guard (filter_dns_safe_ip_addrs), identical to the HTTP bridge — a hostname is resolved once and pinned, restricted non-loopback ranges are refused.

How

  • python.rs: 7 new PythonVfsRpcMethods (SocketConnect/Send/Recv/Close, UdpCreate/Sendto/Recvfrom), port/socketId wire fields, and Socket*/Udp* response payloads.
  • execution.rs: handle_python_socket_rpc_request opens a host TcpStream/UdpSocket per request, stored in a per-process registry. Reads use a short (100 ms) socket read timeout so a recv RPC returns promptly (data, or a timed_out flag) and never stalls the shared sidecar event loop.
  • state.rs: per-process PythonHostSocket registry (separate from the JS runtime's event-driven sockets).
  • runner: socket bridge methods on both RPC bridges + a socket.socket shim whose recv/recvfrom re-poll the host to emulate blocking semantics.

Scope

Outbound only — listeners (bind/listen/accept) are not implemented (they need host-side accept plumbing). Documented as such.

Test

python_runtime_supports_raw_tcp_and_udp_sockets drives a host TCP echo server and a host UDP echo server through Python's stdlib socket module (under the loopback-exempt + allow-all policy). Full python_suite stays green.

Companion docs PR: rivet-dev/agentos#1553.

🤖 Generated with Claude Code

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>
@railway-app railway-app Bot temporarily deployed to secure-exec / secure-exec-pr-140 June 28, 2026 00:08 Destroyed
@railway-app railway-app Bot temporarily deployed to rivet-frontend / secure-exec-pr-140 June 28, 2026 00:08 Destroyed
@railway-app

railway-app Bot commented Jun 28, 2026

Copy link
Copy Markdown

🚅 Deployed to the secure-exec-pr-140 environment in rivet-frontend

Service Status Web Updated (UTC)
secure-exec 😴 Sleeping (View Logs) Jun 28, 2026 at 12:17 am

🚅 Deployed to the secure-exec-pr-140 environment in secure-exec

Service Status Web Updated (UTC)
secure-exec 😴 Sleeping (View Logs) Web Jun 28, 2026 at 12:17 am

@NathanFlurry

Copy link
Copy Markdown
Member Author

Superseded by #142 (combined with the FS-hooks work).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant