Skip to content

Conversation

0div
Copy link
Contributor

@0div 0div commented Sep 10, 2025

Description

Implement a separate process monitoring background routine (i.e. not the one that tracks commands received via GRPC), by leveraging gopsutil to track and define how to handle new processes as they are running and exiting. This is the first step in sending process info to the events endpoint in the context of the internal sandbox events project.

Test

Go test

[e2b-dev/infra/packages/envd] go test ./...

Manual test

In envd's main.go:

go host.MonitorProcesses(1*time.Second, func(processInfo *host.ProcessInfo) error {
	fmt.Printf("[HANDLE PROCESS] %+v\n", processInfo)
	return nil
})
[e2b-dev/infra/packages/envd] $ make build && make start-docker
 
 [...]
 
[HANDLE PROCESS] &{State:exited PID:92 Name:sleep Cmdline:/run/rosetta/rosetta /usr/bin/sleep sleep 10 CreateTime:1757462956600}
[HANDLE PROCESS] &{State:exited PID:88 Name:sleep Cmdline:/run/rosetta/rosetta /usr/bin/sleep sleep 10 CreateTime:1757462956420}
[HANDLE PROCESS] &{State:exited PID:91 Name:sleep Cmdline:/run/rosetta/rosetta /usr/bin/sleep sleep 10 CreateTime:1757462956590}
[HANDLE PROCESS] &{State:running PID:102 Name:bash Cmdline:/bin/bash CreateTime:1757463018860}
[HANDLE PROCESS] &{State:running PID:108 Name:sleep Cmdline:sleep 1 CreateTime:1757463032820}
[HANDLE PROCESS] &{State:exited PID:108 Name:sleep Cmdline:sleep 1 CreateTime:1757463032820}

$ docker exec -it ${ENDV_CONTAINER} /bin/bash
root@dda5af440389 sleep 1

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

linear bot commented Sep 10, 2025

@0div 0div marked this pull request as ready for review September 10, 2025 01:22
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.

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.

Comment on lines +84 to +88
currentPids, err := process.Pids()
if err != nil {
logger.Error().Err(err).Msg("Error getting current processes")
continue
}
Copy link
Member

Choose a reason for hiding this comment

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

Just a quick note:

Can we watch for processes spawned by envd (run, command methods committed from our SDK)? I think monitoring all PIDs, except for some initial ones, will not work as systemd / other daemons can periodically spawn and kill processes, so current pids will be blown by some irrelevant processes.

Copy link
Contributor Author

@0div 0div Sep 11, 2025

Choose a reason for hiding this comment

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

I thought of doing that initially but it wouldn't account for the processes spawned outside of it, one of the goals being to detect anomalous behavior.

…ground-routine-in-envd-that-monitors-newly-created-e2b-3002
@0div 0div marked this pull request as draft September 12, 2025 21:37
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