77 order : 1
88 badge :
99 text : Beta
10- group :
11- label : sandbox
1210head :
1311 - tag : title
1412 content : Overview
@@ -45,74 +43,76 @@ With Sandbox, you can execute Python scripts, run Node.js applications, analyze
4543 ``` typescript
4644 import { getSandbox } from ' @cloudflare/sandbox' ;
4745
48- export default {
49- async fetch(request : Request , env : Env ): Promise <Response > {
50- const sandbox = getSandbox (env .Sandbox , ' user-123' );
51-
52- // Execute a command and get the result
53- const result = await sandbox .exec (' python --version' );
54-
55- return Response .json ({
56- output: result .stdout ,
57- exitCode: result .exitCode ,
58- success: result .success
59- });
60- }
61- };
62- ```
63- </TabItem >
64- <TabItem label = " Code Interpreter" >
65- ``` typescript
66- import { getSandbox } from ' @cloudflare/sandbox' ;
46+ export default {
47+ async fetch(request : Request , env : Env ): Promise <Response > {
48+ const sandbox = getSandbox (env .Sandbox , ' user-123' );
49+
50+ // Execute a command and get the result
51+ const result = await sandbox .exec (' python --version' );
52+
53+ return Response .json ({
54+ output: result .stdout ,
55+ exitCode: result .exitCode ,
56+ success: result .success
57+ });
58+ }
59+ };
60+ ```
61+ </TabItem >
62+ <TabItem label = " Code Interpreter" >
63+ ``` typescript
64+ import { getSandbox } from ' @cloudflare/sandbox' ;
6765
68- export default {
69- async fetch(request : Request , env : Env ): Promise <Response > {
70- const sandbox = getSandbox (env .Sandbox , ' user-123' );
66+ export default {
67+ async fetch(request : Request , env : Env ): Promise <Response > {
68+ const sandbox = getSandbox (env .Sandbox , ' user-123' );
7169
72- // Create a Python execution context
73- const ctx = await sandbox .createCodeContext ({ language: ' python' });
70+ // Create a Python execution context
71+ const ctx = await sandbox .createCodeContext ({ language: ' python' });
72+
73+ // Execute Python code with automatic result capture
74+ const result = await sandbox .runCode (`
7475
75- // Execute Python code with automatic result capture
76- const result = await sandbox .runCode (`
7776import pandas as pd
7877data = {'product': ['A', 'B', 'C'], 'sales': [100, 200, 150]}
7978df = pd.DataFrame(data)
8079df['sales'].sum() # Last expression is automatically returned
8180 ` , { context: ctx });
8281
83- return Response .json ({
84- result: result .results ?.[0 ]?.text ,
85- logs: result .logs
86- });
87- }
88- };
89- ```
90- </TabItem >
91- <TabItem label = " File Operations" >
92- ``` typescript
93- import { getSandbox } from ' @cloudflare/sandbox' ;
94-
95- export default {
96- async fetch(request : Request , env : Env ): Promise <Response > {
97- const sandbox = getSandbox (env .Sandbox , ' user-123' );
82+ return Response .json ({
83+ result: result .results ?.[0 ]?.text ,
84+ logs: result .logs
85+ });
86+ }
87+ };
88+ ```
89+ </TabItem >
90+ <TabItem label = " File Operations" >
91+ ``` typescript
92+ import { getSandbox } from ' @cloudflare/sandbox' ;
93+
94+ export default {
95+ async fetch(request : Request , env : Env ): Promise <Response > {
96+ const sandbox = getSandbox (env .Sandbox , ' user-123' );
97+
98+ // Create a project structure
99+ await sandbox .mkdir (' /workspace/project/src' , { recursive: true });
100+
101+ // Write files
102+ await sandbox .writeFile (
103+ ' /workspace/project/package.json' ,
104+ JSON .stringify ({ name: ' my-app' , version: ' 1.0.0' })
105+ );
106+
107+ // Read a file back
108+ const content = await sandbox .readFile (' /workspace/project/package.json' );
109+
110+ return Response .json ({ content });
111+ }
112+ };
113+ ```
114+ </TabItem >
98115
99- // Create a project structure
100- await sandbox .mkdir (' /workspace/project/src' , { recursive: true });
101-
102- // Write files
103- await sandbox .writeFile (
104- ' /workspace/project/package.json' ,
105- JSON .stringify ({ name: ' my-app' , version: ' 1.0.0' })
106- );
107-
108- // Read a file back
109- const content = await sandbox .readFile (' /workspace/project/package.json' );
110-
111- return Response .json ({ content });
112- }
113- };
114- ```
115- </TabItem >
116116</Tabs >
117117
118118<LinkButton variant = " primary" href = " /sandbox/get-started/" >
@@ -194,7 +194,7 @@ Stateful coordination layer that enables Sandbox to maintain persistent environm
194194
195195<CardGrid >
196196
197- <LinkTitleCard title = " Examples " href = " /sandbox/examples /" icon = " pen" >
197+ <LinkTitleCard title = " Tutorials " href = " /sandbox/tutorials /" icon = " pen" >
198198 Explore complete examples including AI code execution, data analysis, and
199199 interactive environments.
200200</LinkTitleCard >
@@ -207,7 +207,11 @@ Stateful coordination layer that enables Sandbox to maintain persistent environm
207207 Learn about the Sandbox Beta, current status, and upcoming features.
208208</LinkTitleCard >
209209
210- <LinkTitleCard title = " Pricing" href = " /sandbox/platform/pricing/" icon = " document" >
210+ <LinkTitleCard
211+ title = " Pricing"
212+ href = " /sandbox/platform/pricing/"
213+ icon = " document"
214+ >
211215 Understand Sandbox pricing based on the underlying Containers platform.
212216</LinkTitleCard >
213217
@@ -216,13 +220,9 @@ Stateful coordination layer that enables Sandbox to maintain persistent environm
216220 them.
217221</LinkTitleCard >
218222
219- <LinkTitleCard
220- title = " Best Practices"
221- href = " /sandbox/best-practices/"
222- icon = " seti:lock"
223- >
224- Learn security best practices, performance optimization, and production
225- deployment patterns.
223+ <LinkTitleCard title = " How-to Guides" href = " /sandbox/guides/" icon = " seti:lock" >
224+ Learn how to solve specific problems and implement features with the Sandbox
225+ SDK.
226226</LinkTitleCard >
227227
228228<LinkTitleCard
0 commit comments