Skip to content
This repository was archived by the owner on May 26, 2025. It is now read-only.

Commit 5246d53

Browse files
committed
refactor: add 'language' param in codeRun/code_run and remove it from sandbox creation
Signed-off-by: MDzaja <[email protected]>
1 parent 664e5b6 commit 5246d53

File tree

27 files changed

+270
-418
lines changed

27 files changed

+270
-418
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const sandbox = await daytona.create({
2828
})
2929

3030
// Run the code securely inside the sandbox
31-
const response = await sandbox.process.code_run('console.log("Hello World!")')
31+
const response = await sandbox.process.code_run("typescript", 'console.log("Hello World!")')
3232
console.log(response.result)
3333
```
3434

@@ -52,7 +52,7 @@ daytona = Daytona()
5252
sandbox = daytona.create()
5353

5454
# Run the code securely inside the sandbox
55-
response = sandbox.process.code_run('print("Hello World!")')
55+
response = sandbox.process.code_run("python", 'print("Hello World!")')
5656
print(response.result)
5757
```
5858

docs/python-sdk/daytona.mdx

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,11 @@ def create(params: Optional[CreateSandboxParams] = None,
8484
```
8585

8686
Creates Sandboxes with default or custom configurations. You can specify various parameters,
87-
including language, image, resources, environment variables, and volumes for the Sandbox.
87+
including image, resources, environment variables, and volumes for the Sandbox.
8888

8989
**Arguments**:
9090

91-
- `params` _Optional[CreateSandboxParams]_ - Parameters for Sandbox creation. If not provided,
92-
defaults to Python language.
91+
- `params` _Optional[CreateSandboxParams]_ - Parameters for Sandbox creation.
9392
- `timeout` _Optional[float]_ - Timeout (in seconds) for sandbox creation. 0 means no timeout.
9493
Default is 60 seconds.
9594

@@ -114,7 +113,6 @@ sandbox = daytona.create()
114113
Create a custom Sandbox:
115114
```python
116115
params = CreateSandboxParams(
117-
language="python",
118116
name="my-sandbox",
119117
image="debian:12.9",
120118
env_vars={"DEBUG": "true"},
@@ -265,20 +263,6 @@ Stops a Sandbox and waits for it to be stopped.
265263
- `DaytonaError` - If timeout is negative; If Sandbox fails to stop or times out
266264

267265

268-
## CodeLanguage
269-
270-
```python
271-
@dataclass
272-
class CodeLanguage(Enum)
273-
```
274-
275-
Programming languages supported by Daytona
276-
277-
**Enum Members**:
278-
- `PYTHON` ("python")
279-
- `TYPESCRIPT` ("typescript")
280-
- `JAVASCRIPT` ("javascript")
281-
282266
## DaytonaConfig
283267

284268
```python
@@ -339,7 +323,6 @@ resources = SandboxResources(
339323
gpu=1
340324
)
341325
params = CreateSandboxParams(
342-
language="python",
343326
resources=resources
344327
)
345328
```
@@ -354,7 +337,6 @@ Parameters for creating a new Sandbox.
354337

355338
**Attributes**:
356339

357-
- `language` _Optional[CodeLanguage]_ - Programming language for the Sandbox ("python", "javascript", "typescript").
358340
Defaults to "python".
359341
- `id` _Optional[str]_ - Custom identifier for the Sandbox. If not provided, a random ID will be generated.
360342
- `name` _Optional[str]_ - Display name for the Sandbox. Defaults to Sandbox ID if not provided.
@@ -375,7 +357,6 @@ Parameters for creating a new Sandbox.
375357

376358
```python
377359
params = CreateSandboxParams(
378-
language="python",
379360
name="my-sandbox",
380361
env_vars={"DEBUG": "true"},
381362
resources=SandboxResources(cpu=2, memory=4),

docs/python-sdk/process.mdx

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,19 @@ Handles process and code execution within a Sandbox.
1212

1313
**Attributes**:
1414

15-
- `code_toolbox` _SandboxPythonCodeToolbox_ - Language-specific code execution toolbox.
1615
- `toolbox_api` _ToolboxApi_ - API client for Sandbox operations.
1716
- `instance` _SandboxInstance_ - The Sandbox instance this process belongs to.
1817

1918
#### Process.\_\_init\_\_
2019

2120
```python
22-
def __init__(code_toolbox: SandboxPythonCodeToolbox, toolbox_api: ToolboxApi,
23-
instance: SandboxInstance)
21+
def __init__(toolbox_api: ToolboxApi, instance: SandboxInstance)
2422
```
2523

2624
Initialize a new Process instance.
2725

2826
**Arguments**:
2927

30-
- `code_toolbox` _SandboxPythonCodeToolbox_ - Language-specific code execution toolbox.
3128
- `toolbox_api` _ToolboxApi_ - API client for Sandbox operations.
3229
- `instance` _SandboxInstance_ - The Sandbox instance this process belongs to.
3330

@@ -77,7 +74,8 @@ result = sandbox.process.exec("sleep 10", timeout=5)
7774
#### Process.code\_run
7875

7976
```python
80-
def code_run(code: str,
77+
def code_run(language: Literal["python", "typescript", "javascript"],
78+
code: str,
8179
params: Optional[CodeRunParams] = None,
8280
timeout: Optional[int] = None) -> ExecuteResponse
8381
```
@@ -86,6 +84,7 @@ Executes code in the Sandbox using the appropriate language runtime.
8684

8785
**Arguments**:
8886

87+
- `language` _Literal["python", "typescript", "javascript"]_ - Programming language to use.
8988
- `code` _str_ - Code to execute.
9089
- `params` _Optional[CodeRunParams]_ - Parameters for code execution.
9190
- `timeout` _Optional[int]_ - Maximum time in seconds to wait for the code
@@ -105,11 +104,14 @@ Executes code in the Sandbox using the appropriate language runtime.
105104

106105
```python
107106
# Run Python code
108-
response = sandbox.process.code_run('''
109-
x = 10
110-
y = 20
111-
print(f"Sum: {x + y}")
112-
''')
107+
response = sandbox.process.code_run(
108+
language="python",
109+
code='''
110+
x = 10
111+
y = 20
112+
print(f"Sum: {x + y}")
113+
'''
114+
)
113115
print(response.artifacts.stdout) # Prints: Sum: 30
114116
```
115117

@@ -132,7 +134,7 @@ print(response.artifacts.stdout) # Prints: Sum: 30
132134
plt.show()
133135
'''
134136

135-
response = sandbox.process.code_run(code)
137+
response = sandbox.process.code_run("python", code)
136138
chart = response.artifacts.charts[0]
137139

138140
print(f"Type: {chart.type}")
@@ -413,3 +415,17 @@ Parameters for code execution.
413415
- `argv` _Optional[List[str]]_ - Command line arguments
414416
- `env` _Optional[Dict[str, str]]_ - Environment variables
415417

418+
## CodeLanguage
419+
420+
```python
421+
@dataclass
422+
class CodeLanguage(str, Enum)
423+
```
424+
425+
Programming languages supported by Daytona
426+
427+
**Enum Members**:
428+
- `PYTHON` ("python")
429+
- `TYPESCRIPT` ("typescript")
430+
- `JAVASCRIPT` ("javascript")
431+

docs/python-sdk/sandbox.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Represents a Daytona Sandbox.
1414

1515
- `id` _str_ - Unique identifier for the Sandbox.
1616
- `instance` _SandboxInstance_ - The underlying Sandbox instance.
17-
- `code_toolbox` _SandboxCodeToolbox_ - Language-specific toolbox implementation.
1817
- `fs` _FileSystem_ - File system operations interface.
1918
- `git` _Git_ - Git operations interface.
2019
- `process` _Process_ - Process execution interface.
@@ -23,7 +22,7 @@ Represents a Daytona Sandbox.
2322

2423
```python
2524
def __init__(id: str, instance: SandboxInstance, sandbox_api: SandboxApi,
26-
toolbox_api: ToolboxApi, code_toolbox: SandboxCodeToolbox)
25+
toolbox_api: ToolboxApi)
2726
```
2827

2928
Initialize a new Sandbox instance.
@@ -34,7 +33,6 @@ Initialize a new Sandbox instance.
3433
- `instance` _SandboxInstance_ - The underlying Sandbox instance.
3534
- `sandbox_api` _SandboxApi_ - API client for Sandbox operations.
3635
- `toolbox_api` _ToolboxApi_ - API client for toolbox operations.
37-
- `code_toolbox` _SandboxCodeToolbox_ - Language-specific toolbox implementation.
3836

3937
#### Sandbox.info
4038

docs/typescript-sdk/daytona.mdx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ create(params?: CreateSandboxParams, timeout?: number): Promise<Sandbox>
6363
```
6464

6565
Creates Sandboxes with default or custom configurations. You can specify various parameters,
66-
including language, image, resources, environment variables, and volumes for the Sandbox.
66+
including image, resources, environment variables, and volumes for the Sandbox.
6767

6868
**Parameters**:
6969

@@ -85,7 +85,6 @@ const sandbox = await daytona.create();
8585
```ts
8686
// Create a custom sandbox
8787
const params: CreateSandboxParams = {
88-
language: 'typescript',
8988
image: 'node:18',
9089
envVars: {
9190
NODE_ENV: 'development',
@@ -282,16 +281,6 @@ await daytona.stop(sandbox);
282281
***
283282

284283

285-
## CodeLanguage
286-
287-
Supported programming languages for code execution
288-
289-
**Enum Members**:
290-
291-
- `JAVASCRIPT` ("javascript")
292-
- `PYTHON` ("python")
293-
- `TYPESCRIPT` ("typescript")
294-
295284
## CreateSandboxParams
296285

297286
Parameters for creating a new Sandbox.
@@ -304,7 +293,6 @@ Parameters for creating a new Sandbox.
304293
- `id?` _string_ - Optional Sandbox ID. If not provided, a random ID will be generated
305294
- `image?` _string_ - Optional Docker image to use for the Sandbox
306295
- `labels?` _Record\<string, string\>_ - Sandbox labels
307-
- `language?` _string_ - Programming language for direct code execution
308296
- `public?` _boolean_ - Is the Sandbox port preview public
309297
- `resources?` _SandboxResources_ - Resource allocation for the Sandbox
310298
- `target?` _string_ - Target location for the Sandbox
@@ -319,7 +307,6 @@ Parameters for creating a new Sandbox.
319307

320308
```ts
321309
const params: CreateSandboxParams = {
322-
language: 'typescript',
323310
envVars: { NODE_ENV: 'development' },
324311
resources: {
325312
cpu: 2,

docs/typescript-sdk/process.mdx

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,11 @@ Handles process and code execution within a Sandbox.
3636
#### new Process()
3737

3838
```ts
39-
new Process(
40-
codeToolbox: SandboxCodeToolbox,
41-
toolboxApi: ToolboxApi,
42-
instance: SandboxInstance): Process
39+
new Process(toolboxApi: ToolboxApi, instance: SandboxInstance): Process
4340
```
4441

4542
**Parameters**:
4643

47-
- `codeToolbox` _SandboxCodeToolbox_
4844
- `toolboxApi` _ToolboxApi_
4945
- `instance` _SandboxInstance_
5046

@@ -59,6 +55,7 @@ new Process(
5955

6056
```ts
6157
codeRun(
58+
language: "python" | "typescript" | "javascript",
6259
code: string,
6360
params?: CodeRunParams,
6461
timeout?: number): Promise<ExecuteResponse>
@@ -68,6 +65,7 @@ Executes code in the Sandbox using the appropriate language runtime.
6865

6966
**Parameters**:
7067

68+
- `language` _Programming language for the code._ - `"python"` | `"typescript"` | `"javascript"`
7169
- `code` _string_ - Code to execute
7270
- `params?` _CodeRunParams_ - Parameters for code execution
7371
- `timeout?` _number_ - Maximum time in seconds to wait for execution to complete
@@ -84,17 +82,22 @@ Executes code in the Sandbox using the appropriate language runtime.
8482

8583
```ts
8684
// Run TypeScript code
87-
const response = await process.codeRun(`
88-
const x = 10;
89-
const y = 20;
90-
console.log(\`Sum: \${x + y}\`);
91-
`);
85+
const response = await sandbox.process.codeRun(
86+
'typescript',
87+
`
88+
const x = 10;
89+
const y = 20;
90+
console.log(\`Sum: \${x + y}\`);
91+
`
92+
);
9293
console.log(response.artifacts.stdout); // Prints: Sum: 30
9394
```
9495

9596
```ts
9697
// Run Python code with matplotlib
97-
const response = await process.codeRun(`
98+
const response = await sandbox.process.codeRun(
99+
'python',
100+
`
98101
import matplotlib.pyplot as plt
99102
import numpy as np
100103
@@ -108,7 +111,8 @@ plt.xlabel('X-axis (seconds)')
108111
plt.ylabel('Y-axis (amplitude)')
109112
plt.grid(True)
110113
plt.show()
111-
`);
114+
`
115+
);
112116

113117
if (response.artifacts?.charts) {
114118
const chart = response.artifacts.charts[0];
@@ -427,3 +431,17 @@ sessions.forEach(session => {
427431
});
428432
});
429433
```
434+
435+
***
436+
437+
438+
## CodeLanguage
439+
440+
Supported programming languages for code execution
441+
442+
**Enum Members**:
443+
444+
- `JAVASCRIPT` ("javascript")
445+
- `PYTHON` ("python")
446+
- `TYPESCRIPT` ("typescript")
447+

docs/typescript-sdk/sandbox.mdx

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ new Sandbox(
3030
id: string,
3131
instance: SandboxInstance,
3232
sandboxApi: WorkspaceApi,
33-
toolboxApi: ToolboxApi,
34-
codeToolbox: SandboxCodeToolbox): Sandbox
33+
toolboxApi: ToolboxApi): Sandbox
3534
```
3635

3736
Creates a new Sandbox instance
@@ -42,7 +41,6 @@ Creates a new Sandbox instance
4241
- `instance` _SandboxInstance_ - The underlying Sandbox instance
4342
- `sandboxApi` _WorkspaceApi_ - API client for Sandbox operations
4443
- `toolboxApi` _ToolboxApi_ - API client for toolbox operations
45-
- `codeToolbox` _SandboxCodeToolbox_ - Language-specific toolbox implementation
4644

4745

4846
**Returns**:
@@ -421,33 +419,6 @@ or encounters an error.
421419
**Throws**:
422420

423421
- `DaytonaError` - If the sandbox fails to stop within the timeout period.
424-
## SandboxCodeToolbox
425-
426-
Interface defining methods that a code toolbox must implement
427-
428-
### Methods
429-
430-
#### getRunCommand()
431-
432-
```ts
433-
getRunCommand(code: string, params?: CodeRunParams): string
434-
```
435-
436-
Generates a command to run the provided code
437-
438-
**Parameters**:
439-
440-
- `code` _string_
441-
- `params?` _CodeRunParams_
442-
443-
444-
**Returns**:
445-
446-
- `string`
447-
448-
***
449-
450-
451422
## SandboxInfo
452423

453424
Structured information about a Sandbox

0 commit comments

Comments
 (0)