Use OpenAI to generate Python code and execute it securely inside a Declaw sandbox. The LLM runs on the host; only the generated code runs inside the isolated sandbox.
Host process Sandbox (sandbox)─────────────────────────────── ──────────────────────────────────1. Call OpenAI chat API → (isolated)2. Receive generated Python code3. sbx.files.write(code) → /tmp/generated.py written to VM fs4. sbx.commands.run(python3 ...) → Code executes inside the VM5. Read result.stdout ← VM returns stdout/stderr/exit_code6. sbx.kill() VM destroyed
The LLM never runs inside the sandbox. Only the generated code does. This ensures that even if the LLM produces malicious code, it executes in an isolated sandbox with no access to host resources.
import openaifrom declaw import Sandboxclient = openai.OpenAI()task = "Write a Python script that finds all prime numbers under 100 and prints them."response = client.chat.completions.create( model="gpt-4o-mini", messages=[ { "role": "system", "content": ( "You are a code generation agent. Given a task, respond " "ONLY with Python code that accomplishes the task. " "No markdown, no explanation." ), }, {"role": "user", "content": task}, ], temperature=0,)code = strip_code_fences(response.choices[0].message.content or "")sbx = Sandbox.create(template="python", timeout=300)try: sbx.files.write("/tmp/generated.py", code) result = sbx.commands.run("python3 /tmp/generated.py", timeout=30) print(result.stdout)finally: sbx.kill()
A fresh sandbox is created for each task in this example. This is intentional: it ensures that code from one task cannot read files or environment variables left over from a previous task. For long-running sessions where state should persist across tasks, reuse the same sandbox — but understand that state accumulates.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Declaw","description":"Declaw is a security-first sandbox platform for AI agents. Run untrusted code in sandbox microVMs with PII redaction, prompt injection defense, and network policy enforcement.","colors":{"primary":"#0D9373","light":"#07C983","dark":"#0D9373"},"logo":{"light":"https://mintcdn.com/declaw/YB_0u8lW6K_x_PnD/logo/light.svg?fit=max\u0026auto=format\u0026n=YB_0u8lW6K_x_PnD\u0026q=85\u0026s=3a1b3b5d14a7c974db1eda0b8d012499","dark":"https://mintcdn.com/declaw/YB_0u8lW6K_x_PnD/logo/dark.svg?fit=max\u0026auto=format\u0026n=YB_0u8lW6K_x_PnD\u0026q=85\u0026s=564cdf5bfb8abed1949842b56312a3ba"},"favicon":"https://mintcdn.com/declaw/8XHgD2oahu7LIUrQ/favicon.svg?fit=max\u0026auto=format\u0026n=8XHgD2oahu7LIUrQ\u0026q=85\u0026s=c8814a2fdcc2cf40add79906afcd7b5b","api":{"openapi":"openapi.yaml","mdx":{"auth":{"method":"key","name":"X-API-Key"},"server":"https://api.declaw.ai"}},"appearance":{"default":"dark"},"navbar":{"links":[{"href":"https://docs.declaw.ai/mcp","label":"MCP"}],"primary":{"type":"button","label":"Get API Key","href":"https://declaw.ai"}},"footer":{"socials":{"x":"https://x.com/declaw_ai"}},"seo":{"indexing":"navigable"},"styling":{"latex":true},"navigation":{"global":{"anchors":[{"anchor":"Community","icon":"discord","href":"https://discord.gg/bjA5Zs9ZPw"}]},"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"declaw","hasAudioNarration":false,"actualSubdomain":"declaw","customDomains":["docs.declaw.ai"],"gitSource":{"type":"github","owner":"declaw-ai","repo":"declaw-cloud","deployBranch":"main","contentDirectory":"declaw/client_docs","isPrivate":true,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6ad8419f3fe31fb23d51dad1","collectionId":"dfe2e9f0-4a4f-4b22-8ebd-61b3d1c12780","schemaVersion":"v3","latestBuiltDeploymentHistoryId":"6ad8419f3fe31fb23d51dad1"},"entitlements":{"AI_CHAT":{"status":"DISABLED"}},"buildId":"6ad8419f3fe31fb23d51dad1","clientVersion":"0.0.3971","searchFilterCounts":[{"language":"default","tag":"Cookbook","count":89},{"language":"default","tag":"API Reference","count":52},{"language":"default","tag":"Documentation","count":45},{"language":"default","tag":"SDKs","count":32},{"language":"default","tag":"Volumes API","count":21},{"language":"default","tag":"Sandbox API","count":14},{"language":"default","tag":"OpenAI Agents","count":14},{"language":"default","tag":"Security","count":13},{"language":"default","tag":"Python SDK","count":12},{"language":"default","tag":"Filesystem API","count":11}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-v7-file-tree","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"pause-universal-search-reconcile","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"per-site-search-delta","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-private-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-nav-generations","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"byok-sep-25","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-agent-model-picker","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-updated-9-15","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"isAtlas":false,"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"cookbook/agent-in-sandbox/openai","slug":"/cookbook/agent-in-sandbox/openai","pageMetadata":{"title":"Agent in Sandbox (OpenAI)","sidebarTitle":"OpenAI","description":"Use OpenAI to generate Python code and execute it securely inside a Declaw sandbox. The LLM runs on the host; only the generated code runs inside the isolated sandbox.","href":"/cookbook/agent-in-sandbox/openai"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Use OpenAI to generate Python code and execute it securely inside a Declaw sandbox. The LLM runs on the host; only the generated code runs inside the isolated sandbox.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,p:`p`,pre:`pre`,span:`span`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Note}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Note)_missingMdxReference(`Note`,true);return _jsxs(_Fragment,{children:[_jsx(Heading,{level:`2`,id:`what-you’ll-learn`,children:`What You’ll Learn`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`The fundamental pattern: LLM on host, code execution in sandbox`}),`\n`,_jsx(_components.li,{children:`How to strip markdown code fences from LLM output before executing`}),`\n`,_jsx(_components.li,{children:`How to create and destroy a fresh sandbox per task for strong isolation`}),`\n`,_jsx(_components.li,{children:`Demo mode: run the full workflow without an OpenAI API key`}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`prerequisites`,children:`Prerequisites`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`Declaw running locally or in the cloud (see `,_jsx(_components.a,{href:`/deployment/overview`,children:`Deployment`}),`)`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`DECLAW_API_KEY`}),` and `,_jsx(_components.code,{children:`DECLAW_DOMAIN`}),` set in your environment`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`OPENAI_API_KEY`}),` set in your environment (optional — demo mode runs without it)`]}),`\n`]}),`\n`,_jsx(Note,{children:_jsx(_components.p,{children:`This example is available in Python. TypeScript support coming soon.`})}),`\n`,_jsx(Heading,{level:`2`,id:`code-walkthrough`,children:`Code Walkthrough`}),`\n`,_jsx(Heading,{level:`3`,id:`architecture`,children:`Architecture`}),`\n`,_jsx(CodeBlock,{numberOfLines:`9`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`9`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`Host process Sandbox (sandbox)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`─────────────────────────────── ──────────────────────────────────`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`1. Call OpenAI chat API → (isolated)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`2. Receive generated Python code`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`3. sbx.files.write(code) → /tmp/generated.py written to VM fs`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`4. sbx.commands.run(python3 ...) → Code executes inside the VM`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`5. Read result.stdout ← VM returns stdout/stderr/exit_code`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`6. sbx.kill() VM destroyed`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(_components.p,{children:`The LLM never runs inside the sandbox. Only the generated code does. This ensures that even if the LLM produces malicious code, it executes in an isolated sandbox with no access to host resources.`}),`\n`,_jsxs(Heading,{level:`3`,id:`live-mode-requires-openai_api_key`,children:[`Live mode (requires `,_jsx(_components.code,{children:`OPENAI_API_KEY`}),`)`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`32`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`32`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` openai`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` declaw `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Sandbox`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`client `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` openai.OpenAI()`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`task `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Write a Python script that finds all prime numbers under 100 and prints them.\"`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` client.chat.completions.create(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"gpt-4o-mini\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` messages`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"system\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: (`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"You are a code generation agent. Given a task, respond \"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"ONLY with Python code that accomplishes the task. \"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"No markdown, no explanation.\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ),`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"role\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"content\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: task},`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` temperature`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`code `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` strip_code_fences(response.choices[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].message.content `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`or`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`sbx `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Sandbox.create(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`template`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"python\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`timeout`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`300`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sbx.files.write(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"/tmp/generated.py\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, code)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` result `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sbx.commands.run(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"python3 /tmp/generated.py\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`timeout`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`30`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(result.stdout)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`finally`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sbx.kill()`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`stripping-code-fences`,children:`Stripping code fences`}),`\n`,_jsx(_components.p,{children:`LLMs often wrap code in markdown fences even when instructed not to. Always strip them before executing:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`8`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`8`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` strip_code_fences`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`code`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) -> `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"\"\"Remove markdown code fences from LLM output.\"\"\"`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` code `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` code.strip()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` code.startswith(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:'\"```\"'}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` code `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.join(code.split(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:])`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` code.endswith(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:'\"```\"'}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` code `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.join(code.split(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\n`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)[:`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`-`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`])`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` code.strip()`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`demo-mode-no-api-key-required`,children:`Demo mode (no API key required)`}),`\n`,_jsx(_components.p,{children:`The example ships with a demo mode that uses hardcoded “LLM output” so you can verify the sandbox execution path without an API key:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`21`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`21`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Simulated LLM output for a data analysis task`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`simulated_code `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` textwrap.dedent(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\"\"`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`\\\\`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` import statistics`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` sales_data = [`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` {\"month\": \"Jan\", \"revenue\": 12500},`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` {\"month\": \"Feb\", \"revenue\": 15300},`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` # ...`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` ]`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` revenues = [d[\"revenue\"] for d in sales_data]`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` print(f\"Average: {statistics.mean(revenues)}\")`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` print(f\"Median: {statistics.median(revenues)}\")`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\"\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`sbx `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Sandbox.create(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`template`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"python\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`timeout`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`300`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sbx.files.write(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"/tmp/generated.py\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, simulated_code)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` result `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sbx.commands.run(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"python3 /tmp/generated.py\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`timeout`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`30`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(result.stdout)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`finally`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` sbx.kill()`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`mode-selection`,children:`Mode selection`}),`\n`,_jsx(_components.p,{children:`The example auto-detects whether to run live or demo:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`5`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`5`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`api_key `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` os.environ.get(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"OPENAI_API_KEY\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` not`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` api_key `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`or`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` api_key `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"your-openai-api-key\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` demo_mode()`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`else`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` live_mode()`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`expected-output-demo-mode`,children:`Expected Output (demo mode)`}),`\n`,_jsx(CodeBlock,{numberOfLines:`22`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`22`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`Agent in Sandbox (OpenAI) Example`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`============================================================`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`OPENAI_API_KEY not set — running in demo mode.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`--- Demo: Simulating OpenAI agent workflow ---`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` Simulated task: Analyze a dataset and compute summary statistics`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` Creating sandbox and executing...`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` Sandbox created: sbx-abc123`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` Output:`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` === Sales Data Analysis ===`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` total_revenue: 95500`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` average_revenue: 15916.67`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` median_revenue: 15300`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` std_deviation: 3152.32`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` min_month: Mar`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` max_month: Jun`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` growth_pct: 68.0`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` Sandbox sbx-abc123 killed.`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(Heading,{level:`2`,id:`security-note`,children:`Security Note`}),`\n`,_jsx(_components.p,{children:`A fresh sandbox is created for each task in this example. This is intentional: it ensures that code from one task cannot read files or environment variables left over from a previous task. For long-running sessions where state should persist across tasks, reuse the same sandbox — but understand that state accumulates.`})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Agent in Sandbox (OpenAI)","sidebarTitle":"OpenAI","description":"Use OpenAI to generate Python code and execute it securely inside a Declaw sandbox. The LLM runs on the host; only the generated code runs inside the isolated sandbox.","href":"/cookbook/agent-in-sandbox/openai"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"What You’ll Learn","slug":"what-you’ll-learn","depth":2,"children":[]},{"title":"Prerequisites","slug":"prerequisites","depth":2,"children":[]},{"title":"Code Walkthrough","slug":"code-walkthrough","depth":2,"children":[{"title":"Architecture","slug":"architecture","depth":3,"children":[]},{"title":"Live mode (requires OPENAI_API_KEY)","slug":"live-mode-requires-openai_api_key","depth":3,"children":[]},{"title":"Stripping code fences","slug":"stripping-code-fences","depth":3,"children":[]},{"title":"Demo mode (no API key required)","slug":"demo-mode-no-api-key-required","depth":3,"children":[]},{"title":"Mode selection","slug":"mode-selection","depth":3,"children":[]}]},{"title":"Expected Output (demo mode)","slug":"expected-output-demo-mode","depth":2,"children":[]},{"title":"Security Note","slug":"security-note","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"declaw","siteName":"Declaw","title":"Agent in Sandbox (OpenAI) - Declaw","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-04-18T21:07:46.850Z","originalFileLocation":"cookbook/agent-in-sandbox/openai.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"dark\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Use OpenAI to generate Python code and execute it securely inside a Declaw sandbox. The LLM runs on the host; only the generated code runs inside the isolated sandbox.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Declaw\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/declaw/5qZO9alYltiMvEad/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/declaw/5qZO9alYltiMvEad/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/declaw/5qZO9alYltiMvEad/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/declaw/5qZO9alYltiMvEad/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/declaw/5qZO9alYltiMvEad/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/declaw/5qZO9alYltiMvEad/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/declaw/5qZO9alYltiMvEad/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/declaw/5qZO9alYltiMvEad/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/declaw/5qZO9alYltiMvEad/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Agent in Sandbox (OpenAI) - Declaw\">\u003cmeta data-mint-head property=\"og:description\" content=\"Use OpenAI to generate Python code and execute it securely inside a Declaw sandbox. The LLM runs on the host; only the generated code runs inside the isolated sandbox.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Declaw\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.declaw.ai/cookbook/agent-in-sandbox/openai\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://declaw.mintlify.app/_mintlify/api/og/v2?division=Agent-in-Sandbox\u0026amp;title=Agent+in+Sandbox+%28OpenAI%29\u0026amp;description=Use+OpenAI+to+generate+Python+code+and+execute+it+securely+inside+a+Declaw+sandbox.+The+LLM+runs+on+the+host%3B+only+the+generated+code+runs+inside+the+isolated+s\u0026amp;theme=e908f26a500811980d5ccfa6\u0026amp;signature=d9009801210139768895b5a3865a128d201829e6f7968b232df0d28eb2c0a70c\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Agent in Sandbox (OpenAI) - Declaw\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Use OpenAI to generate Python code and execute it securely inside a Declaw sandbox. The LLM runs on the host; only the generated code runs inside the isolated sandbox.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://declaw.mintlify.app/_mintlify/api/og/v2?division=Agent-in-Sandbox\u0026amp;title=Agent+in+Sandbox+%28OpenAI%29\u0026amp;description=Use+OpenAI+to+generate+Python+code+and+execute+it+securely+inside+a+Declaw+sandbox.+The+LLM+runs+on+the+host%3B+only+the+generated+code+runs+inside+the+isolated+s\u0026amp;theme=e908f26a500811980d5ccfa6\u0026amp;signature=d9009801210139768895b5a3865a128d201829e6f7968b232df0d28eb2c0a70c\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/declaw/5qZO9alYltiMvEad/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Declaw\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#0D9373\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.declaw.ai/cookbook/agent-in-sandbox/openai\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/cookbook/agent-in-sandbox/openai.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.declaw.ai/#organization\",\"name\":\"Declaw\",\"url\":\"https://docs.declaw.ai\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/declaw/YB_0u8lW6K_x_PnD/logo/light.svg?fit=max\u0026auto=format\u0026n=YB_0u8lW6K_x_PnD\u0026q=85\u0026s=3a1b3b5d14a7c974db1eda0b8d012499\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.declaw.ai#website\",\"name\":\"Declaw\",\"url\":\"https://docs.declaw.ai\",\"publisher\":{\"@id\":\"https://docs.declaw.ai/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.declaw.ai/cookbook/agent-in-sandbox/openai#webpage\",\"url\":\"https://docs.declaw.ai/cookbook/agent-in-sandbox/openai\",\"name\":\"Agent in Sandbox (OpenAI)\",\"description\":\"Use OpenAI to generate Python code and execute it securely inside a Declaw sandbox. The LLM runs on the host; only the generated code runs inside the isolated sandbox.\",\"dateModified\":\"2026-04-18T21:07:46.850Z\",\"isPartOf\":{\"@id\":\"https://docs.declaw.ai#website\"},\"breadcrumb\":{\"@id\":\"https://docs.declaw.ai/cookbook/agent-in-sandbox/openai#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.declaw.ai/cookbook/agent-in-sandbox/openai#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Agent-in-Sandbox\",\"item\":\"https://docs.declaw.ai/cookbook/agent-in-sandbox/basic\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Agent in Sandbox (OpenAI)\",\"item\":\"https://docs.declaw.ai/cookbook/agent-in-sandbox/openai\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.declaw.ai/cookbook/agent-in-sandbox/openai#article\",\"headline\":\"Agent in Sandbox (OpenAI)\",\"name\":\"Agent in Sandbox (OpenAI)\",\"description\":\"Use OpenAI to generate Python code and execute it securely inside a Declaw sandbox. The LLM runs on the host; only the generated code runs inside the isolated sandbox.\",\"url\":\"https://docs.declaw.ai/cookbook/agent-in-sandbox/openai\",\"mainEntityOfPage\":{\"@id\":\"https://docs.declaw.ai/cookbook/agent-in-sandbox/openai#webpage\"},\"dateModified\":\"2026-04-18T21:07:46.850Z\",\"publisher\":{\"@id\":\"https://docs.declaw.ai/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.declaw.ai#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Declaw\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"Declaw","nav":{"global":{"anchors":[{"anchor":"Community","icon":"discord","href":"https://discord.gg/bjA5Zs9ZPw"}]},"tabs":[{"tab":"Documentation","pages":[{"title":"Documentation","href":"/introduction"}]},{"tab":"API Reference","pages":[{"title":"API Reference","href":"/api-reference/overview"}]},{"tab":"SDKs","pages":[{"title":"SDKs","href":"/sdks/python/overview"}]},{"tab":"Cookbook","groups":[{"group":"Getting Started","pages":[{"title":"Cookbook","sidebarTitle":"Overview","href":"/cookbook/overview"},{"title":"Hello World","sidebarTitle":"Hello World","href":"/cookbook/getting-started/hello-world"},{"title":"Sandbox Lifecycle","sidebarTitle":"Sandbox Lifecycle","href":"/cookbook/getting-started/sandbox-lifecycle"},{"title":"Multi-Sandbox Isolation","sidebarTitle":"Multi-Sandbox Isolation","href":"/cookbook/getting-started/multi-sandbox-isolation"}]},{"group":"Built-in Templates","pages":[{"title":"base — shell tools end-to-end","sidebarTitle":"base","href":"/cookbook/templates/base-shell-tools"},{"title":"python — pandas CSV analysis","sidebarTitle":"python","href":"/cookbook/templates/python-pandas-analysis"},{"title":"node — TypeScript script","sidebarTitle":"node","href":"/cookbook/templates/node-typescript-script"},{"title":"code-interpreter — executing LLM-generated Python","sidebarTitle":"code-interpreter","href":"/cookbook/templates/code-interpreter-data-viz"},{"title":"web-dev — Next.js + Tailwind build","sidebarTitle":"web-dev","href":"/cookbook/templates/web-dev-nextjs"},{"title":"devops — terraform + kubectl + docker","sidebarTitle":"devops","href":"/cookbook/templates/devops-terraform-kubectl"},{"title":"mcp-server — FastMCP hello-tool","sidebarTitle":"mcp-server","href":"/cookbook/templates/mcp-server-fastmcp"},{"title":"ai-agent — frameworks check","sidebarTitle":"ai-agent","href":"/cookbook/templates/ai-agent-frameworks"},{"title":"ai-agent — fintech KYC with CrewAI (sandboxed)","sidebarTitle":"ai-agent — KYC (CrewAI)","href":"/cookbook/templates/ai-agent-kyc-crewai"},{"title":"ai-agent — health-tech prior auth with LangGraph (sandboxed)","sidebarTitle":"ai-agent — Prior auth (LangGraph)","href":"/cookbook/templates/ai-agent-prior-auth-langgraph"}]},{"group":"Commands","pages":[{"title":"Run Command","sidebarTitle":"Run Command","href":"/cookbook/commands/run-command"},{"title":"Stream Command","sidebarTitle":"Stream Command","href":"/cookbook/commands/stream-command"},{"title":"Background Process","sidebarTitle":"Background Process","href":"/cookbook/commands/background-process"},{"title":"Multi-Language Execution","sidebarTitle":"Multi-Language Execution","href":"/cookbook/commands/multi-language-execution"}]},{"group":"PTY","pages":[{"title":"Interactive sandbox shell in your local terminal","sidebarTitle":"Interactive terminal","href":"/cookbook/pty/interactive-terminal"},{"title":"PTY REPL demo","sidebarTitle":"REPL demo","href":"/cookbook/pty/pty-repl"},{"title":"ANSI features and TUI detection","sidebarTitle":"ANSI features","href":"/cookbook/pty/pty-features"},{"title":"Live monitoring dashboard","sidebarTitle":"Dashboard","href":"/cookbook/pty/pty-dashboard"},{"title":"Visual effects showcase","sidebarTitle":"Visual showcase","href":"/cookbook/pty/pty-showcase"},{"title":"Cursor-style agent with PTY handoff","sidebarTitle":"Agent with PTY","href":"/cookbook/pty/agent-with-pty"}]},{"group":"OpenAI Agents","pages":[{"title":"OpenAI Agents SDK — overview","href":"/cookbook/openai-agents/overview"},{"title":"OpenAI Agents SDK — quick start","sidebarTitle":"Quick start","href":"/cookbook/openai-agents-quickstart"},{"title":"OpenAI Agents — PII redaction end-to-end","sidebarTitle":"PII redaction","href":"/cookbook/openai-agents-security"},{"title":"Data analyst agent","href":"/cookbook/openai-agents/data-analyst"},{"title":"Code reviewer agent","href":"/cookbook/openai-agents/code-reviewer"},{"title":"Customer support triage","href":"/cookbook/openai-agents/customer-support"},{"title":"Web scraper agent","href":"/cookbook/openai-agents/web-scraper"},{"title":"TypeScript API builder","href":"/cookbook/openai-agents/typescript-api"},{"title":"DevOps auditor","href":"/cookbook/openai-agents/devops-audit"},{"title":"ML training agent","href":"/cookbook/openai-agents/ml-model"},{"title":"Custom transformation rules","href":"/cookbook/openai-agents/transformations"},{"title":"Shared Volume, Multi-Agent Fan-Out","sidebarTitle":"Shared Volume Multi-Agent","href":"/cookbook/openai-agents/shared-volume-multi-agent"},{"title":"Shell-only capability for older models","sidebarTitle":"Shell-only (gpt-4.1)","href":"/cookbook/openai-agents/quickstart-shell-only"},{"title":"PTY access through the OpenAI adapter","sidebarTitle":"PTY access","href":"/cookbook/openai-agents/pty"}]},{"group":"Filesystem","pages":[{"title":"File Operations","sidebarTitle":"File Operations","href":"/cookbook/filesystem/file-operations"},{"title":"Binary File Operations","sidebarTitle":"Binary File Operations","href":"/cookbook/filesystem/binary-file-operations"},{"title":"Upload Dataset \u0026 Analyze","sidebarTitle":"Upload Dataset \u0026 Analyze","href":"/cookbook/filesystem/upload-dataset-analyze"},{"title":"Download Results","sidebarTitle":"Download Results","href":"/cookbook/filesystem/download-results"}]},{"group":"Volumes","pages":[{"title":"Upload and Attach a Volume","sidebarTitle":"Upload and Attach","href":"/cookbook/volumes/upload-and-attach"},{"title":"Share a Volume Across Sandboxes","sidebarTitle":"Share Across Sandboxes","href":"/cookbook/volumes/share-across-sandboxes"},{"title":"List and Delete Volumes","sidebarTitle":"List and Delete","href":"/cookbook/volumes/list-and-delete"}]},{"group":"Network Policies","pages":[{"title":"Network Deny All","sidebarTitle":"Network Deny All","href":"/cookbook/network/network-deny-all"},{"title":"Network Domain Allowlist","sidebarTitle":"Domain Allowlist","href":"/cookbook/network/network-domain-allowlist"},{"title":"Network Exfiltration Prevention","sidebarTitle":"Exfiltration Prevention","href":"/cookbook/network/network-exfiltration-prevention"},{"title":"Network Metadata Blocking","sidebarTitle":"Metadata Blocking","href":"/cookbook/network/network-metadata-blocking"},{"title":"Layer-4 network enforcement","sidebarTitle":"L4 enforcement","href":"/cookbook/network/network-l4-enforcement"}]},{"group":"PII Protection","pages":[{"title":"PII Redaction","sidebarTitle":"PII Redaction","href":"/cookbook/pii/pii-redaction"},{"title":"PII Actions","sidebarTitle":"PII Actions","href":"/cookbook/pii/pii-actions"},{"title":"PII Rehydration","sidebarTitle":"PII Rehydration","href":"/cookbook/pii/pii-rehydration"},{"title":"PII Streaming Rehydration","sidebarTitle":"Streaming Rehydration","href":"/cookbook/pii/pii-streaming-rehydration"},{"title":"SSN-specific redaction","sidebarTitle":"SSN redaction","href":"/cookbook/pii/pii-ssn-redaction"},{"title":"PII in JSON request bodies","sidebarTitle":"JSON body safety","href":"/cookbook/pii/pii-json-body-safety"}]},{"group":"Security Features","pages":[{"title":"Injection Defense","sidebarTitle":"Injection Defense","href":"/cookbook/security/injection-defense"},{"title":"Transformation Rules","sidebarTitle":"Transformation Rules","href":"/cookbook/security/transformation-rules"},{"title":"Audit Logging","sidebarTitle":"Audit Logging","href":"/cookbook/security/audit-logging"}]},{"group":"LLM Providers","pages":[{"title":"OpenAI Code Interpreter","sidebarTitle":"OpenAI","href":"/cookbook/llm-providers/openai-code-interpreter"},{"title":"Anthropic Code Interpreter","sidebarTitle":"Anthropic","href":"/cookbook/llm-providers/anthropic-code-interpreter"},{"title":"Groq Code Interpreter","sidebarTitle":"Groq","href":"/cookbook/llm-providers/groq-code-interpreter"},{"title":"Gemini Code Interpreter","sidebarTitle":"Gemini","href":"/cookbook/llm-providers/gemini-code-interpreter"},{"title":"Local LLM Code Interpreter","sidebarTitle":"Local LLM","href":"/cookbook/llm-providers/local-llm-code-interpreter"}]},{"group":"Framework Integrations","pages":[{"title":"LangGraph + Declaw","sidebarTitle":"LangGraph","href":"/cookbook/frameworks/langgraph-python"},{"title":"CrewAI + Declaw","sidebarTitle":"CrewAI","href":"/cookbook/frameworks/crewai-python"},{"title":"AutoGen + Declaw","sidebarTitle":"AutoGen","href":"/cookbook/frameworks/autogen-python"},{"title":"OpenAI Agents SDK + Declaw","sidebarTitle":"OpenAI Agents SDK","href":"/cookbook/frameworks/openai-agents-python"},{"title":"Agno (Phidata) + Declaw","sidebarTitle":"Agno (Phidata)","href":"/cookbook/frameworks/phidata-python"},{"title":"Haystack + Declaw","sidebarTitle":"Haystack","href":"/cookbook/frameworks/haystack-python"},{"title":"Mastra + Declaw","sidebarTitle":"Mastra","href":"/cookbook/frameworks/mastra-typescript"}]},{"group":"Agent-in-Sandbox","pages":[{"title":"Agent in Sandbox (Basic)","sidebarTitle":"Basic","description":"Upload an autonomous agent script into an isolated Declaw sandbox, execute it, and read back structured results.","href":"/cookbook/agent-in-sandbox/basic"},{"title":"Agent in Sandbox (OpenAI)","sidebarTitle":"OpenAI","href":"/cookbook/agent-in-sandbox/openai"},{"title":"Agent in Sandbox (Anthropic)","sidebarTitle":"Anthropic","description":"Use Anthropic Claude to generate Python code and execute it securely inside a Declaw sandbox. The model runs on the host; only the generated code runs inside the isolated sandbox.","href":"/cookbook/agent-in-sandbox/anthropic"},{"title":"Agent in Sandbox (CrewAI)","sidebarTitle":"CrewAI","href":"/cookbook/agent-in-sandbox/crewai"},{"title":"Agent in Sandbox with Network Policy","sidebarTitle":"With Network Policy","href":"/cookbook/agent-in-sandbox/with-network-policy"},{"title":"Agent in Sandbox (Fully Secured)","sidebarTitle":"Secured","href":"/cookbook/agent-in-sandbox/secured"}]},{"group":"Real-World Patterns","pages":[{"title":"CI/CD Pipeline in a Sandbox","sidebarTitle":"CI/CD Sandbox","href":"/cookbook/patterns/ci-cd-sandbox"},{"title":"Data Analysis in a Sandbox","sidebarTitle":"Data Analysis","href":"/cookbook/patterns/data-analysis"},{"title":"Web Scraping with Network Policy","sidebarTitle":"Web Scraping","href":"/cookbook/patterns/web-scraping-sandbox"},{"title":"HTTP Server in a Sandbox","sidebarTitle":"MCP Server in Sandbox","href":"/cookbook/patterns/mcp-server-in-sandbox"},{"title":"Multi-Agent Sandboxed Pipeline","sidebarTitle":"Multi-Agent Pipeline","href":"/cookbook/patterns/multi-agent-sandboxed"},{"title":"Git Clone and Fix","sidebarTitle":"Git Clone and Fix","href":"/cookbook/patterns/git-clone-and-fix"},{"title":"URL helper methods","sidebarTitle":"URL helpers","href":"/cookbook/patterns/url-helpers"},{"title":"Interactive stdio","sidebarTitle":"Interactive stdio","href":"/cookbook/patterns/stdio-interactive"}]},{"group":"Security Demos","pages":[{"title":"Prompt Injection Attack Defense","sidebarTitle":"Prompt Injection","href":"/cookbook/security-demos/prompt-injection-attack"},{"title":"Supply Chain Attack Isolation","sidebarTitle":"Supply Chain Attack","href":"/cookbook/security-demos/supply-chain-attack"},{"title":"Credential Leak Prevention","sidebarTitle":"Credential Leak Prevention","href":"/cookbook/security-demos/credential-leak-prevention"},{"title":"With vs Without Declaw","sidebarTitle":"With vs Without Declaw","href":"/cookbook/security-demos/with-vs-without-declaw"}]}]}]},"title":"Agent in Sandbox (OpenAI) - Declaw","buildId":"dpl_DFJrtvUi8HS5F9nkooKuDJsuD5BM","deploymentId":"dpl_DFJrtvUi8HS5F9nkooKuDJsuD5BM","dynamics":[],"chunks":[]}