Skip to content

Commit 1a5d5dd

Browse files
feat(e2b-execution): add remote code execution to support Python + Imports (#1226)
* feat(e2b-execution): add remote code execution via e2b * ux improvements * fix streaming * progress * fix tooltip text * make supported languages an enum * fix error handling * fix tests
1 parent 9de0d91 commit 1a5d5dd

File tree

17 files changed

+658
-70
lines changed

17 files changed

+658
-70
lines changed

apps/sim/app/api/function/execute/route.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ describe('Function Execute API Route', () => {
3232
createLogger: vi.fn().mockReturnValue(mockLogger),
3333
}))
3434

35+
vi.doMock('@/lib/execution/e2b', () => ({
36+
executeInE2B: vi.fn().mockResolvedValue({
37+
result: 'e2b success',
38+
stdout: 'e2b output',
39+
sandboxId: 'test-sandbox-id',
40+
}),
41+
}))
42+
3543
mockRunInContext.mockResolvedValue('vm success')
3644
mockCreateContext.mockReturnValue({})
3745
})
@@ -45,6 +53,7 @@ describe('Function Execute API Route', () => {
4553
const req = createMockRequest('POST', {
4654
code: 'return "Hello World"',
4755
timeout: 5000,
56+
useLocalVM: true,
4857
})
4958

5059
const { POST } = await import('@/app/api/function/execute/route')
@@ -74,6 +83,7 @@ describe('Function Execute API Route', () => {
7483
it('should use default timeout when not provided', async () => {
7584
const req = createMockRequest('POST', {
7685
code: 'return "test"',
86+
useLocalVM: true,
7787
})
7888

7989
const { POST } = await import('@/app/api/function/execute/route')
@@ -93,6 +103,7 @@ describe('Function Execute API Route', () => {
93103
it('should resolve environment variables with {{var_name}} syntax', async () => {
94104
const req = createMockRequest('POST', {
95105
code: 'return {{API_KEY}}',
106+
useLocalVM: true,
96107
envVars: {
97108
API_KEY: 'secret-key-123',
98109
},
@@ -108,6 +119,7 @@ describe('Function Execute API Route', () => {
108119
it('should resolve tag variables with <tag_name> syntax', async () => {
109120
const req = createMockRequest('POST', {
110121
code: 'return <email>',
122+
useLocalVM: true,
111123
params: {
112124
email: { id: '123', subject: 'Test Email' },
113125
},
@@ -123,6 +135,7 @@ describe('Function Execute API Route', () => {
123135
it('should NOT treat email addresses as template variables', async () => {
124136
const req = createMockRequest('POST', {
125137
code: 'return "Email sent to user"',
138+
useLocalVM: true,
126139
params: {
127140
email: {
128141
from: 'Waleed Latif <waleed@sim.ai>',
@@ -141,6 +154,7 @@ describe('Function Execute API Route', () => {
141154
it('should only match valid variable names in angle brackets', async () => {
142155
const req = createMockRequest('POST', {
143156
code: 'return <validVar> + "<invalid@email.com>" + <another_valid>',
157+
useLocalVM: true,
144158
params: {
145159
validVar: 'hello',
146160
another_valid: 'world',
@@ -178,6 +192,7 @@ describe('Function Execute API Route', () => {
178192

179193
const req = createMockRequest('POST', {
180194
code: 'return <email>',
195+
useLocalVM: true,
181196
params: gmailData,
182197
})
183198

@@ -200,6 +215,7 @@ describe('Function Execute API Route', () => {
200215

201216
const req = createMockRequest('POST', {
202217
code: 'return <email>',
218+
useLocalVM: true,
203219
params: complexEmailData,
204220
})
205221

@@ -214,6 +230,7 @@ describe('Function Execute API Route', () => {
214230
it('should handle custom tool execution with direct parameter access', async () => {
215231
const req = createMockRequest('POST', {
216232
code: 'return location + " weather is sunny"',
233+
useLocalVM: true,
217234
params: {
218235
location: 'San Francisco',
219236
},
@@ -245,6 +262,7 @@ describe('Function Execute API Route', () => {
245262
it('should handle timeout parameter', async () => {
246263
const req = createMockRequest('POST', {
247264
code: 'return "test"',
265+
useLocalVM: true,
248266
timeout: 10000,
249267
})
250268

@@ -262,6 +280,7 @@ describe('Function Execute API Route', () => {
262280
it('should handle empty parameters object', async () => {
263281
const req = createMockRequest('POST', {
264282
code: 'return "no params"',
283+
useLocalVM: true,
265284
params: {},
266285
})
267286

@@ -295,6 +314,7 @@ SyntaxError: Invalid or unexpected token
295314

296315
const req = createMockRequest('POST', {
297316
code: 'const obj = {\n name: "test",\n description: "This has a missing closing quote\n};\nreturn obj;',
317+
useLocalVM: true,
298318
timeout: 5000,
299319
})
300320

@@ -338,6 +358,7 @@ SyntaxError: Invalid or unexpected token
338358

339359
const req = createMockRequest('POST', {
340360
code: 'const obj = null;\nreturn obj.someMethod();',
361+
useLocalVM: true,
341362
timeout: 5000,
342363
})
343364

@@ -379,6 +400,7 @@ SyntaxError: Invalid or unexpected token
379400

380401
const req = createMockRequest('POST', {
381402
code: 'const x = 42;\nreturn undefinedVariable + x;',
403+
useLocalVM: true,
382404
timeout: 5000,
383405
})
384406

@@ -409,6 +431,7 @@ SyntaxError: Invalid or unexpected token
409431

410432
const req = createMockRequest('POST', {
411433
code: 'return "test";',
434+
useLocalVM: true,
412435
timeout: 5000,
413436
})
414437

@@ -445,6 +468,7 @@ SyntaxError: Invalid or unexpected token
445468

446469
const req = createMockRequest('POST', {
447470
code: 'const a = 1;\nconst b = 2;\nconst c = 3;\nconst d = 4;\nreturn a + b + c + d;',
471+
useLocalVM: true,
448472
timeout: 5000,
449473
})
450474

@@ -476,6 +500,7 @@ SyntaxError: Invalid or unexpected token
476500

477501
const req = createMockRequest('POST', {
478502
code: 'const obj = {\n name: "test"\n// Missing closing brace',
503+
useLocalVM: true,
479504
timeout: 5000,
480505
})
481506

@@ -496,6 +521,7 @@ SyntaxError: Invalid or unexpected token
496521
// This tests the escapeRegExp function indirectly
497522
const req = createMockRequest('POST', {
498523
code: 'return {{special.chars+*?}}',
524+
useLocalVM: true,
499525
envVars: {
500526
'special.chars+*?': 'escaped-value',
501527
},
@@ -512,6 +538,7 @@ SyntaxError: Invalid or unexpected token
512538
// Test with complex but not circular data first
513539
const req = createMockRequest('POST', {
514540
code: 'return <complexData>',
541+
useLocalVM: true,
515542
params: {
516543
complexData: {
517544
special: 'chars"with\'quotes',

0 commit comments

Comments
 (0)