File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ def __init__(
4242 self .debug = debug or ConnectionConfig ._debug ()
4343 self .api_key = api_key or ConnectionConfig ._api_key ()
4444 self .access_token = access_token or ConnectionConfig ._access_token ()
45- self .headers = headers
45+ self .headers = headers or {}
4646
4747 self .request_timeout = ConnectionConfig ._get_request_timeout (
4848 REQUEST_TIMEOUT ,
@@ -75,6 +75,8 @@ def _get_request_timeout(
7575 def get_request_timeout (self , request_timeout : Optional [float ] = None ):
7676 return self ._get_request_timeout (self .request_timeout , request_timeout )
7777
78+ def get_request_base_headers (self ):
79+ return self .headers or {}
7880
7981Username = Literal ["root" , "user" ]
8082"""
Original file line number Diff line number Diff line change @@ -112,3 +112,11 @@ async def test_watch_file(async_sandbox: AsyncSandbox):
112112
113113 with pytest .raises (SandboxException ):
114114 await async_sandbox .files .watch_dir (filename , on_event = lambda e : None )
115+
116+ async def test_watch_file_with_secured_envd (template ):
117+ sbx = await AsyncSandbox .create (template , timeout = 30 , secure = True )
118+ try :
119+ await sbx .files .watch_dir ("/home/user/" , on_event = lambda e : None )
120+ await sbx .files .write ("test_watch.txt" , "This file will be watched." )
121+ finally :
122+ await sbx .kill ()
Original file line number Diff line number Diff line change @@ -120,3 +120,24 @@ async def test_write_to_non_existing_directory(async_sandbox: AsyncSandbox):
120120
121121 read_content = await async_sandbox .files .read (filename )
122122 assert read_content == content
123+
124+ async def test_write_with_secured_envd (template ):
125+ filename = "non_existing_dir/test_write.txt"
126+ content = "This should succeed too."
127+
128+ sbx = await AsyncSandbox .create (template , timeout = 30 , secure = True )
129+ try :
130+ assert await sbx .is_running ()
131+ assert sbx ._envd_version is not None
132+ assert sbx ._envd_access_token is not None
133+
134+ await sbx .files .write (filename , content )
135+
136+ exists = await sbx .files .exists (filename )
137+ assert exists
138+
139+ read_content = await sbx .files .read (filename )
140+ assert read_content == content
141+
142+ finally :
143+ await sbx .kill ()
Original file line number Diff line number Diff line change 1+ import pytest
2+
3+ from e2b import AsyncSandbox
4+
5+ async def test_start_secured (template ):
6+ sbx = await AsyncSandbox .create (template , timeout = 5 , secure = True )
7+ try :
8+ assert await sbx .is_running ()
9+ assert sbx ._envd_version is not None
10+ assert sbx ._envd_access_token is not None
11+ finally :
12+ await sbx .kill ()
Original file line number Diff line number Diff line change @@ -109,3 +109,11 @@ def test_watch_file(sandbox: Sandbox):
109109
110110 with pytest .raises (SandboxException ):
111111 sandbox .files .watch_dir (filename )
112+
113+ def test_watch_file_with_secured_envd (template ):
114+ sbx = Sandbox (template , timeout = 30 , secrue = True )
115+ try :
116+ sbx .files .watch_dir ("/home/user/" )
117+ sbx .files .write ("test_watch.txt" , "This file will be watched." )
118+ finally :
119+ sbx .kill ()
Original file line number Diff line number Diff line change 11import io
22
33from e2b .sandbox .filesystem .filesystem import EntryInfo
4+ from e2b .sandbox_sync .main import Sandbox
45
56
67def test_write_text_file (sandbox ):
@@ -119,3 +120,25 @@ def test_write_to_non_existing_directory(sandbox):
119120
120121 read_content = sandbox .files .read (filename )
121122 assert read_content == content
123+
124+ def test_write_with_secured_envd (template ):
125+ filename = "non_existing_dir/test_write.txt"
126+ content = "This should succeed too."
127+
128+ sbx = Sandbox (template , timeout = 30 , secrue = True )
129+ try :
130+ assert sbx .is_running ()
131+ assert sbx ._envd_version is not None
132+ assert sbx ._envd_access_token is not None
133+
134+ sbx .files .write (filename , content )
135+
136+ exists = sbx .files .exists (filename )
137+ assert exists
138+
139+ read_content = sbx .files .read (filename )
140+ assert read_content == content
141+
142+ finally :
143+ sbx .kill ()
144+
Original file line number Diff line number Diff line change 1+ import pytest
2+
3+ from e2b import Sandbox
4+
5+
6+ def test_start_secured (template ):
7+ sbx = Sandbox (template , timeout = 5 , secrue = True )
8+ try :
9+ assert sbx .is_running ()
10+ assert sbx ._envd_version is not None
11+ assert sbx ._envd_access_token is not None
12+ finally :
13+ sbx .kill ()
You can’t perform that action at this time.
0 commit comments