Skip to content

Conversation

0div
Copy link
Contributor

@0div 0div commented Sep 3, 2025

Description

Setup networking in sandbox for events endpoint and handle sandbox events at the orchestrator level.

  • implement sandbox event proxy server to capture http requests to events endpoints inside sandboxes
  • create handler abstraction
  • map sandboxIPs-to-sandboxIDs
  • introduce consts.go file in orchestrator and add the sandbox event IP and port

Test

[infra]
$ make build-and-upload/envd # with mmds changes 
$ make build-and-upload/template-manager # with changes from https://github.com/e2b-dev/infra/pull/1107
$ make build-and-upload/orchestrator # with changes from this PR 
$ make plan
$ make apply 

[E2B/template/base]
$ e2b template build

[Sandbox]
user@e2b:~$ cat /etc/hosts
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::  ip6-localnet
ff00::  ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.1.1 e2b.local
203.0.113.0 events.e2b.dev 

$ e2b sbx sp base
user@e2b:~$ curl -X POST http://events.e2b.dev/proc -d '{ "pid": 123 }'

{"event_ack": true }

@0div 0div self-assigned this Sep 3, 2025
Copy link

linear bot commented Sep 3, 2025

@0div 0div marked this pull request as ready for review September 4, 2025 02:17
@0div 0div changed the title Handle sandbox events at the orchestrator level Handle internal sandbox events in orchestrator Sep 4, 2025
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@0div
Copy link
Contributor Author

0div commented Sep 9, 2025

@sitole @dobrac , i made the /etc/hosts update dynamically with new MMDS event address field. I tried a few IPs from local link range (169.254.0.1, 169.254.0.7) but it doesn't work, so i kept it to TEST-NET-3 IP for now

@0div 0div changed the title Handle internal sandbox events in orchestrator Handle internal sandbox events from sandboxes in orchestrator Sep 9, 2025
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@0div 0div requested a review from sitole September 11, 2025 22:40
@0div
Copy link
Contributor Author

0div commented Sep 11, 2025

@sitole once #1107 is merged, i can add integration test here

cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: IP Extraction Fails on IPv6 Addresses

The IP address extraction from r.RemoteAddr using strings.Split(addr, ":")[0] is unreliable. It incorrectly parses IPv6 addresses (e.g., [::1]:port results in [::1 or [) and is fragile, as RemoteAddr's format isn't guaranteed to be ip:port. This can lead to an incorrect sandboxIP.

packages/orchestrator/internal/events/sandbox_events_handlers.go#L30-L32

func (h *DefaultSandboxEventHandler) HandlerFunc(w http.ResponseWriter, r *http.Request) {
addr := r.RemoteAddr
sandboxIP := strings.Split(addr, ":")[0]

Fix in Cursor Fix in Web


Bug: Redis Client Nil Checks Inconsistent

Several sandboxEventStore methods, such as GetSandboxID and DelSandboxIP, don't check if redisClient is nil before use, unlike SetSandboxIP. This inconsistency could lead to nil pointer panics if the client isn't initialized.

packages/orchestrator/internal/events/sandbox_events_store.go#L54-L67

func (c *sandboxEventStore) SetSandboxIP(ctx context.Context, sandboxID string, sandboxIP string) error {
if c.redisClient == nil {
return fmt.Errorf("redisClient is nil")
}
return c.redisClient.Set(ctx, IPPrefix+sandboxIP, sandboxID, cacheTL).Err()
}
func (c *sandboxEventStore) GetSandboxID(ctx context.Context, sandboxIP string) (string, error) {
return c.redisClient.Get(ctx, IPPrefix+sandboxIP).Result()
}
func (c *sandboxEventStore) DelSandboxIP(ctx context.Context, sandboxIP string) error {
return c.redisClient.Del(ctx, IPPrefix+sandboxIP).Err()
}

Fix in Cursor Fix in Web


@sitole
Copy link
Member

sitole commented Sep 22, 2025

#1107 is merged so we can rebase this one.
Probably you can build on top of #1233 that adds gin http server for hyperloop server.

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.

2 participants