Open
Description
Describe the bug
I don't understand what commands.run
timeouts are supposed to do
To Reproduce
Steps to reproduce the behavior:
Using timeout
an exception is raised but the command continues to run:
from time import sleep
from e2b_code_interpreter import Sandbox
import logging
logger = logging.getLogger(__name__)
with Sandbox() as sbx:
try:
logger.info("Running sleep 10")
sbx.commands.run("sleep 10", timeout=1)
logger.info("Sleep 10 finished")
except Exception as e:
logger.error(e)
for i in range(10):
logger.info("%d seconds", i)
logger.info(sbx.commands.list())
sleep(1)
2024-12-11 09:30:06,703 - INFO - Running sleep 10
2024-12-11 09:31:06,913 - ERROR - context deadline exceeded: This error is likely due to exceeding 'timeoutMs' — the total time a long running request (like process or directory watch) can be active. It can be modified by passing 'timeoutMs' when making the request. Use '0' to disable the timeout.
2024-12-11 09:31:06,913 - INFO - 0 seconds
2024-12-11 09:31:07,077 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user'), ProcessInfo(pid=922, tag='', cmd='/bin/bash', args=['-l', '-c', 'sleep 10'], envs={}, cwd='')]
2024-12-11 09:31:08,082 - INFO - 1 seconds
2024-12-11 09:31:08,202 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user'), ProcessInfo(pid=922, tag='', cmd='/bin/bash', args=['-l', '-c', 'sleep 10'], envs={}, cwd='')]
2024-12-11 09:31:09,206 - INFO - 2 seconds
2024-12-11 09:31:09,321 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user'), ProcessInfo(pid=922, tag='', cmd='/bin/bash', args=['-l', '-c', 'sleep 10'], envs={}, cwd='')]
2024-12-11 09:31:10,327 - INFO - 3 seconds
2024-12-11 09:31:10,450 - INFO - [ProcessInfo(pid=922, tag='', cmd='/bin/bash', args=['-l', '-c', 'sleep 10'], envs={}, cwd=''), ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user')]
2024-12-11 09:31:11,451 - INFO - 4 seconds
2024-12-11 09:31:11,574 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user'), ProcessInfo(pid=922, tag='', cmd='/bin/bash', args=['-l', '-c', 'sleep 10'], envs={}, cwd='')]
2024-12-11 09:31:12,579 - INFO - 5 seconds
2024-12-11 09:31:12,693 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user'), ProcessInfo(pid=922, tag='', cmd='/bin/bash', args=['-l', '-c', 'sleep 10'], envs={}, cwd='')]
2024-12-11 09:31:13,698 - INFO - 6 seconds
2024-12-11 09:31:13,818 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user'), ProcessInfo(pid=922, tag='', cmd='/bin/bash', args=['-l', '-c', 'sleep 10'], envs={}, cwd='')]
2024-12-11 09:31:14,823 - INFO - 7 seconds
2024-12-11 09:31:14,940 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user'), ProcessInfo(pid=922, tag='', cmd='/bin/bash', args=['-l', '-c', 'sleep 10'], envs={}, cwd='')]
2024-12-11 09:31:15,945 - INFO - 8 seconds
2024-12-11 09:31:16,063 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user')]
2024-12-11 09:31:17,068 - INFO - 9 seconds
2024-12-11 09:31:17,179 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user')]
Using request_timeout
does not appear to do anything:
from time import sleep
from e2b_code_interpreter import Sandbox
import logging
logger = logging.getLogger(__name__)
with Sandbox() as sbx:
try:
logger.info("Running sleep 10")
sbx.commands.run("sleep 10", request_timeout=1) # <- changed line
logger.info("Sleep 10 finished")
except Exception as e:
logger.error(e)
for i in range(10):
logger.info("%d seconds", i)
logger.info(sbx.commands.list())
sleep(1)
2024-12-11 09:34:15,703 - INFO - Running sleep 10
2024-12-11 09:34:25,895 - INFO - Sleep 10 finished
2024-12-11 09:34:25,896 - INFO - 0 seconds
2024-12-11 09:34:26,010 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user')]
2024-12-11 09:34:27,016 - INFO - 1 seconds
2024-12-11 09:34:27,132 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user')]
2024-12-11 09:34:28,137 - INFO - 2 seconds
2024-12-11 09:34:28,252 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user')]
2024-12-11 09:34:29,257 - INFO - 3 seconds
2024-12-11 09:34:29,373 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user')]
2024-12-11 09:34:30,376 - INFO - 4 seconds
2024-12-11 09:34:30,489 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user')]
2024-12-11 09:34:31,489 - INFO - 5 seconds
2024-12-11 09:34:31,602 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user')]
2024-12-11 09:34:32,607 - INFO - 6 seconds
2024-12-11 09:34:32,723 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user')]
2024-12-11 09:34:33,728 - INFO - 7 seconds
2024-12-11 09:34:33,841 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user')]
2024-12-11 09:34:34,846 - INFO - 8 seconds
2024-12-11 09:34:34,960 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user')]
2024-12-11 09:34:35,965 - INFO - 9 seconds
2024-12-11 09:34:36,084 - INFO - [ProcessInfo(pid=580, tag='startCmd', cmd='/bin/bash', args=['-l', '-c', '/root/.jupyter/start-up.sh'], envs={}, cwd='/home/user')]
2
Expected behavior
- I would expect the job to be killed when
timeout
is exceeded - I would expect something to happen when
request_timeout
is exceeded
Maybe I'm misunderstanding what these are expected to do. Either way I don't understand the docs
timeout: Timeout for the command connection in seconds. Using 0 will not limit the command connection time
request_timeout: Timeout for the request in seconds
Questions:
- What is the expected behaviour of
timeout
andrequest_timeout
? What exceptions can they throw if they are exceeded? And what happens to the running command when they are exceeded? - What is the expected behaviour if the Sandbox timeout is exceeded? Is the Sandbox killed? Are running command killed? What happens to subsequent attempts to run command or read files?
- What is the expected behaviour if
sbx.files.write
request_timeout
is exceeded? When can this happen? Will the write attempt continue to run?
Thanks!