Skip to content

Commit 3dcfa22

Browse files
clean up agent example
1 parent 2452cc2 commit 3dcfa22

1 file changed

Lines changed: 3 additions & 12 deletions

File tree

docs/sandbox/auto-resume.mdx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ print(f"Preview URL: https://{preview_host}")
109109

110110
### Agent/tool execution
111111

112-
For queued tasks or tool calls, create once, store the sandbox ID, and reconnect per task. If the sandbox is paused, `connect` resumes it.
112+
For queued tasks or tool calls, create once and keep using the same sandbox handle. If it is paused, it will auto-resume when you run the next command.
113113

114114
<CodeGroup>
115115
```js JavaScript & TypeScript
@@ -123,14 +123,10 @@ const sandbox = await Sandbox.create({
123123
resumeOn: 'any',
124124
},
125125
})
126-
const sandboxId = sandbox.sandboxId
127126

128127
// Later: called for each agent/tool task
129128
async function runToolTask(command) {
130-
const worker = await Sandbox.connect(sandboxId, {
131-
timeoutMs: 5 * 60 * 1000,
132-
})
133-
const result = await worker.commands.run(command)
129+
const result = await sandbox.commands.run(command)
134130
return result.stdout
135131
}
136132

@@ -147,15 +143,10 @@ sandbox = Sandbox.create(
147143
"resume_on": "any",
148144
},
149145
)
150-
sandbox_id = sandbox.sandbox_id
151146

152147
# Later: called for each agent/tool task
153148
def run_tool_task(command: str) -> str:
154-
worker = Sandbox.connect(
155-
sandbox_id,
156-
timeout=5 * 60,
157-
)
158-
result = worker.commands.run(command)
149+
result = sandbox.commands.run(command)
159150
return result.stdout
160151

161152
print(run_tool_task('python -c "print(2 + 2)"'))

0 commit comments

Comments
 (0)